PLAZMAstudios commited on
Commit
6d2ea1f
·
verified ·
1 Parent(s): b301967

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +20 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ model_name = "cardiffnlp/twitter-roberta-base-sentiment-latest"
5
+
6
+ def analyze_sentiment(text):
7
+ classifier = pipeline('sentiment-analysis', model=model_name, use_auth_token=None)
8
+ result = classifier(text)
9
+ return [{"label": res['label'], "score": f"{res['score']:.2f}"} for res in result]
10
+
11
+ with gr.Blocks() as demo:
12
+ gr.Markdown("# Sentiment Analyzer")
13
+ gr.Markdown("Powered by cardiffnlp/twitter-roberta-base-sentiment-latest")
14
+ text_input = gr.Textbox(label="Text", placeholder="Enter text to analyze...")
15
+ output = gr.JSON(label="Sentiment Result")
16
+ btn = gr.Button("Analyze")
17
+ btn.click(fn=analyze_sentiment, inputs=text_input, outputs=output)
18
+
19
+ if __name__ == "__main__":
20
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch