straightline777 commited on
Commit
02f2ec8
·
verified ·
1 Parent(s): e3def36

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -33
app.py DELETED
@@ -1,33 +0,0 @@
1
-
2
- import gradio as gr
3
- from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
4
-
5
- # Load your model and tokenizer from local paths
6
- model_path = '.'
7
- tokenizer_path = '.'
8
-
9
- model_sentiment = AutoModelForSequenceClassification.from_pretrained(model_path)
10
- tokenizer_sentiment = AutoTokenizer.from_pretrained(tokenizer_path)
11
-
12
- # Initialize the pipeline
13
- clf = pipeline("text-classification", model=model_sentiment, tokenizer=tokenizer_sentiment)
14
-
15
- # Define the sentiment analysis function
16
- def analyze_sentiment(text):
17
- predictions = clf(text)
18
- label_mapping = {'LABEL_0': 'Negative', 'LABEL_1': 'Neutral', 'LABEL_2': 'Positive'}
19
- predicted_label = label_mapping[predictions[0]['label']]
20
- confidence = f"{predictions[0]['score'] * 100:.2f}%"
21
- return predicted_label, confidence
22
-
23
- # Create the Gradio interface
24
- interface = gr.Interface(
25
- fn=analyze_sentiment,
26
- inputs=gr.Textbox(lines=2, placeholder="Enter a tweet here..."),
27
- outputs=[gr.Textbox(label="Predicted Label"), gr.Textbox(label="Confidence")],
28
- title="Covid Vaccine Tweet Sentiments",
29
- description="These models were trained to detect how a user feels about the covid vaccines based on their tweets (text)."
30
- )
31
-
32
- if __name__ == "__main__":
33
- interface.launch()