shouq0i commited on
Commit
f7ff258
·
verified ·
1 Parent(s): eeee747

Upload demo.py

Browse files
Files changed (1) hide show
  1. demo.py +48 -0
demo.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """demo.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/19sodc0ANzqRgZ0VzMGXr4YQ3fvUvxyjv
8
+ """
9
+
10
+ !pip install gradio --quiet
11
+ !pip install transformers --quiet
12
+
13
+ # Use a pipeline as a high-level helper
14
+ from transformers import pipeline
15
+
16
+ sentiment_analysis = pipeline("text-classification", model="avichr/heBERT_sentiment_analysis")
17
+ def analyze_sentiment(text):
18
+ results = sentiment_analysis(text)
19
+ for result in results:
20
+ print(f"Label: {result['label']}, Score: {result['score']}")
21
+
22
+ texts = [
23
+ "Worst rental I ever got"
24
+ "I really enjoyed my stay !"
25
+
26
+ ]
27
+
28
+ analyze_sentiment(texts)
29
+
30
+ !pip install gradio
31
+
32
+ import gradio as gr
33
+ from transformers import pipeline
34
+
35
+
36
+
37
+ interface = gr.Interface(
38
+ fn=analyze_sentiment,
39
+ inputs=gr.Textbox(lines=2, placeholder="Enter your review or statement here..."),
40
+ outputs=[
41
+ gr.Textbox(label="Sentiment"),
42
+ gr.Number(label="Score")
43
+ ],
44
+ title="Sentiment Analysis Score"
45
+ )
46
+
47
+
48
+ interface.launch()