Spaces:
Runtime error
Runtime error
fixed some parsing issues, optimized payload delivery to reduce prediction time
Browse filesthis commit includes, some bug fixes and text formatting, to the previous version.
app.py
CHANGED
@@ -1,25 +1,30 @@
|
|
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 |
-
|
10 |
|
11 |
|
12 |
def predict(image):
|
13 |
cap = pipeline('image-to-text')
|
14 |
-
|
|
|
15 |
|
16 |
-
|
17 |
-
def sentiment_analysis(phrase):
|
18 |
pipe = pipeline('text-classification')
|
19 |
-
|
20 |
-
return
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
return output
|
24 |
|
25 |
|
@@ -27,13 +32,12 @@ input = gr.inputs.Image(
|
|
27 |
label="Upload your Image and wait for 8-12 seconds!", type='pil', optional=False)
|
28 |
output = gr.outputs.Textbox(label="Captions")
|
29 |
|
30 |
-
title = "Content
|
31 |
|
32 |
interface = gr.Interface(
|
33 |
fn=predict,
|
34 |
inputs=input,
|
35 |
-
|
36 |
-
outputs= output,
|
37 |
title=title,
|
38 |
|
39 |
)
|
|
|
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 |
+
caption = cap(image)
|
14 |
+
|
15 |
|
16 |
+
def sentiment_analysis(shortened):
|
|
|
17 |
pipe = pipeline('text-classification')
|
18 |
+
senti = pipe(shortened)
|
19 |
+
return senti
|
20 |
+
caption_string = str(caption)
|
21 |
+
shortened = caption_string.replace("[{'generated_text': '" , "The image is of, ")
|
22 |
+
shortened = shortened.replace("'}]" , "")
|
23 |
+
sentiment = sentiment_analysis(shortened)
|
24 |
+
sentiment_string = ''.join(str(e) for e in sentiment)
|
25 |
+
formated_senti = sentiment_string.replace("{'label': ", ", The Tone of the image(sentiment) after analysisng the caption is that is it is ")
|
26 |
+
formated_senti = formated_senti.replace("'score': ", "in nature with an average percentage of ")
|
27 |
+
output = shortened + formated_senti[0:-2] + '%'
|
28 |
return output
|
29 |
|
30 |
|
|
|
32 |
label="Upload your Image and wait for 8-12 seconds!", type='pil', optional=False)
|
33 |
output = gr.outputs.Textbox(label="Captions")
|
34 |
|
35 |
+
title = "Content-Mod API UI "
|
36 |
|
37 |
interface = gr.Interface(
|
38 |
fn=predict,
|
39 |
inputs=input,
|
40 |
+
outputs=output,
|
|
|
41 |
title=title,
|
42 |
|
43 |
)
|