| from transformers import pipeline |
|
|
| |
| def huggingface_hello_world(): |
| |
| generator = pipeline('text-generation', model='gpt2') |
| |
| |
| hello_response = generator("Hello, how are you today?", max_length=50, num_return_sequences=1) |
| |
| |
| print("Model's Hello World Response:") |
| print(hello_response[0]['generated_text']) |
|
|
| |
| def huggingface_sentiment_hello(): |
| |
| classifier = pipeline('sentiment-analysis') |
| |
| |
| sentiment = classifier("Hello World! This is a nice day.") |
| |
| |
| print("\nSentiment Analysis of 'Hello World':") |
| print(f"Sentiment: {sentiment[0]['label']}") |
| print(f"Confidence: {sentiment[0]['score']:.2f}") |
|
|
| |
| if __name__ == "__main__": |
| huggingface_hello_world() |
| huggingface_sentiment_hello() |