Spaces:
Sleeping
Sleeping
| # -*- coding: utf-8 -*- | |
| """app.ipynb | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1ADkU3rLDhb2hQ79cia8wCKiaYrFuw_a- | |
| Ein einfaches Sentiment-Analyse-Modell (es testet die Benutzer Eingabe auf die "Stimmung" über Gradio) | |
| """ | |
| # pip install transformers datasets gradio | |
| # Extrahiert erstmal die ersten 5 Bewertungen aus dem Trainingsteil des Datasets und führt eine Analyse aus | |
| from datasets import load_dataset | |
| from transformers import pipeline | |
| import gradio as gr | |
| dataset = load_dataset("yelp_polarity") | |
| classifier = pipeline("sentiment-analysis") | |
| sample_reviews = dataset['train']['text'][:5] | |
| results = classifier(sample_reviews) | |
| for review, result in zip(sample_reviews, results): | |
| print(f"Review: {review}\nSentiment: {result['label']} (Confidence: {result['score']:.2f})\n") | |
| def analyze_sentiment(text): | |
| return classifier(text)[0] | |
| iface = gr.Interface(fn=analyze_sentiment, | |
| inputs="text", | |
| outputs="json", | |
| live=True, | |
| title="Sentiment Analysis", | |
| description="Geben Sie einen Text ein, um die Stimmung zu analysieren.") | |
| iface.launch() | |