Tolga commited on
Commit
2fce71e
1 Parent(s): 1bd94fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -1
app.py CHANGED
@@ -1,3 +1,60 @@
1
  import gradio as gr
 
 
2
 
3
- gr.Interface.load("models/tkurtulus/Turkish-AI-rlines-SentimentAnalysis").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
 
5
+ model = pipeline(task="sentiment-analysis", model="tkurtulus/Turkish-AI-rlines-SentimentAnalysis")
6
+
7
+ def sentiment_analysis(text):
8
+ res = model(text)[0]
9
+ res_label = {}
10
+ if res["label"] == "positive":
11
+ res_label["positive"] = res["score"]
12
+ res_label["negative"] = 1 - res["score"]
13
+ res_label["neutral"] = 1 - res["score"]
14
+ if res["label"] == "negative":
15
+ res_label["negative"] = res["score"]
16
+ res_label["positive"] = 1 - res["score"]
17
+ res_label["neutral"] = 1 - res["score"]
18
+ if res["label"] == "neutral":
19
+ res_label["neutral"] = res["score"]
20
+ res_label["positive"] = 1 - res["score"]
21
+ res_label["negative"] = 1 - res["score"]
22
+ return res_label
23
+
24
+ custom_css = """
25
+ #component-0 {
26
+ max-width: 600px;
27
+ margin: 0 auto;
28
+ }
29
+
30
+ h1,h2 {
31
+ text-align: center;
32
+ }
33
+
34
+ a {
35
+ color: #77b3ee !important;
36
+ text-decoration: none !important;
37
+ }
38
+
39
+ a:hover {
40
+ text-decoration: underline !important;
41
+ }
42
+ """
43
+
44
+ browser_tab_title = "Sentiment Analysis"
45
+ intro_markdown = """## Sentiment Analysis
46
+
47
+ Using the [distilbert-base-uncased-finetuned-sst-2-english](https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english) model, trained on movie reviews."""
48
+
49
+ with gr.Blocks(title=browser_tab_title, css=custom_css) as demo:
50
+ with gr.Row():
51
+ with gr.Column():
52
+ title = gr.Markdown(intro_markdown)
53
+ text_input = gr.Textbox(placeholder="Enter a positive or negative sentence here...", label="Text")
54
+ label_output = gr.Label(label="Sentiment outcome")
55
+ button_run = gr.Button("Compute sentiment")
56
+ button_run.click(sentiment_analysis, inputs=text_input, outputs=label_output)
57
+ gr.Examples(["That's great!", "The movie was bad.", "How are you"], text_input)
58
+
59
+ if __name__ == "__main__":
60
+ demo.launch()