gsar78 commited on
Commit
1014652
·
verified ·
1 Parent(s): 32c1c21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -1,8 +1,20 @@
1
  import gradio as gr
 
 
2
 
3
- iface = gr.Interface.load("models/gsar78/Greek_Sentiment")
 
4
 
5
- iface.launch(
 
 
 
 
 
 
 
 
 
6
  title="Hellenic Sentiment AI",
7
  description=None,
8
  article=None,
@@ -18,4 +30,6 @@ iface.launch(
18
  show_input=True,
19
  show_output=True,
20
  footer="Development by Geo Sar"
21
- )
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
4
 
5
+ model = AutoModelForSequenceClassification.from_pretrained("gsar78/Greek_Sentiment")
6
+ tokenizer = AutoTokenizer.from_pretrained("gsar78/Greek_Sentiment")
7
 
8
+ def predict(text):
9
+ inputs = tokenizer(text, return_tensors="pt")
10
+ outputs = model(**inputs)
11
+ scores = torch.nn.functional.softmax(outputs.logits, dim=1)
12
+ return {"Positive": scores[:, 1].item(), "Negative": scores[:, 0].item()}
13
+
14
+ iface = gr.Interface(
15
+ fn=predict,
16
+ inputs="text",
17
+ outputs="label",
18
  title="Hellenic Sentiment AI",
19
  description=None,
20
  article=None,
 
30
  show_input=True,
31
  show_output=True,
32
  footer="Development by Geo Sar"
33
+ )
34
+
35
+ iface.launch()