Spaces:
Runtime error
Runtime error
added sentiment analysis to the generated captions
Browse filesadded an api call that return the sentiment analysis (by "cardiffnlp/twitter-xlm-roberta-base-sentiment" )of the generated captions to the existing model. refined the text output.
app.py
CHANGED
@@ -1,18 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
import warnings
|
4 |
import logging
|
5 |
warnings.simplefilter('ignore')
|
6 |
logging.disable(logging.WARNING)
|
7 |
|
8 |
-
|
9 |
|
10 |
|
11 |
def predict(image):
|
12 |
cap = pipeline('image-to-text')
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
input = gr.inputs.Image(
|
@@ -25,9 +33,8 @@ interface = gr.Interface(
|
|
25 |
fn=predict,
|
26 |
inputs=input,
|
27 |
theme="grass",
|
28 |
-
outputs=output,
|
29 |
title=title,
|
30 |
-
flagging_options=["correct", "just okay", "wrong"],
|
31 |
|
32 |
)
|
33 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
|
4 |
import warnings
|
5 |
import logging
|
6 |
warnings.simplefilter('ignore')
|
7 |
logging.disable(logging.WARNING)
|
8 |
|
9 |
+
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
10 |
|
11 |
|
12 |
def predict(image):
|
13 |
cap = pipeline('image-to-text')
|
14 |
+
genereated_dict = cap(image)
|
15 |
+
|
16 |
+
final = str(genereated_dict)
|
17 |
+
def sentiment_analysis(phrase):
|
18 |
+
pipe = pipeline('text-classification')
|
19 |
+
sentiment = pipe(phrase)
|
20 |
+
return str(senti)
|
21 |
+
senti = sentiment_analysis(final)
|
22 |
+
output = final[20:-2]
|
23 |
+
return output
|
24 |
|
25 |
|
26 |
input = gr.inputs.Image(
|
|
|
33 |
fn=predict,
|
34 |
inputs=input,
|
35 |
theme="grass",
|
36 |
+
outputs= output,
|
37 |
title=title,
|
|
|
38 |
|
39 |
)
|
40 |
interface.launch()
|