barflyman commited on
Commit
a7cd89b
·
verified ·
1 Parent(s): a1f5223

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """app.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1ADkU3rLDhb2hQ79cia8wCKiaYrFuw_a-
8
+
9
+ Ein einfaches Sentiment-Analyse-Modell (es testet die Benutzer Eingabe auf die "Stimmung" über Gradio)
10
+ """
11
+
12
+ pip install transformers datasets gradio
13
+
14
+ # Extrahiert erstmal die ersten 5 Bewertungen aus dem Trainingsteil des Datasets und führt eine Analyse aus
15
+
16
+ from datasets import load_dataset
17
+ from transformers import pipeline
18
+ import gradio as gr
19
+
20
+ dataset = load_dataset("yelp_polarity")
21
+
22
+ classifier = pipeline("sentiment-analysis")
23
+
24
+ sample_reviews = dataset['train']['text'][:5]
25
+
26
+ results = classifier(sample_reviews)
27
+
28
+ for review, result in zip(sample_reviews, results):
29
+ print(f"Review: {review}\nSentiment: {result['label']} (Confidence: {result['score']:.2f})\n")
30
+
31
+ def analyze_sentiment(text):
32
+ return classifier(text)[0]
33
+
34
+ iface = gr.Interface(fn=analyze_sentiment,
35
+ inputs="text",
36
+ outputs="json",
37
+ live=True,
38
+ title="Sentiment Analysis",
39
+ description="Geben Sie einen Text ein, um die Stimmung zu analysieren.")
40
+
41
+
42
+ iface.launch()
43
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ datasets
3
+ gradio