thak123 commited on
Commit
0833e94
1 Parent(s): 01a2860

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -1,32 +1,44 @@
1
  import numpy as np
2
  import os
3
  import gradio as gr
 
 
4
 
5
  os.environ["WANDB_DISABLED"] = "true"
6
 
7
  from datasets import load_dataset, load_metric
8
  from transformers import (
9
  AutoConfig,
10
- # AutoModelForSequenceClassification,
11
  AutoTokenizer,
12
  TrainingArguments,
13
  logging,
14
  pipeline
15
  )
16
 
 
 
 
 
 
 
 
 
17
 
18
- analyzer = pipeline(
19
- "sentiment-analysis", model="FFZG-cleopatra/M2SA"
20
- )
21
 
22
- def predict_sentiment(x):
23
- print(analyzer(x))
24
- return "test" #|label2id[analyzer(x)[0]["label"]]
 
 
 
 
 
25
 
26
 
27
  interface = gr.Interface(
28
- fn=predict_sentiment,
29
- inputs='text',
30
  outputs=['text'],
31
  title='Multilingual-Multimodal-Sentiment-Analysis',
32
  examples= ["I love tea","I hate coffee"],
 
1
  import numpy as np
2
  import os
3
  import gradio as gr
4
+ import torch
5
+ from PIL import image
6
 
7
  os.environ["WANDB_DISABLED"] = "true"
8
 
9
  from datasets import load_dataset, load_metric
10
  from transformers import (
11
  AutoConfig,
12
+ AutoModelForSequenceClassification,
13
  AutoTokenizer,
14
  TrainingArguments,
15
  logging,
16
  pipeline
17
  )
18
 
19
+ id2label = {0: "negative", 1: "neutral", 2: "positive"}
20
+ label2id = {"negative": 0, "neutral": 1, "positive": 2}
21
+
22
+ model = AutoModelForSequenceClassification.from_pretrained(
23
+ model="FFZG-cleopatra/M2SA",
24
+ num_labels=3, id2label=id2label,
25
+ label2id=label2id
26
+ )
27
 
 
 
 
28
 
29
+ def predict_sentiment(text, image):
30
+ print(text, image)
31
+ prediction = None
32
+ with torch.no_grad():
33
+ model(x)
34
+ print(analyzer(x))
35
+
36
+ return prediction
37
 
38
 
39
  interface = gr.Interface(
40
+ fn=lambda text, image: predict_sentiment(text, image),,
41
+ inputs=[gr.inputs.Textbox(),gr.inputs.Image(shape=(224, 224))]
42
  outputs=['text'],
43
  title='Multilingual-Multimodal-Sentiment-Analysis',
44
  examples= ["I love tea","I hate coffee"],