Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ logging.disable(logging.WARNING)
|
|
7 |
|
8 |
|
9 |
|
10 |
-
|
11 |
def predict(image):
|
12 |
cap = pipeline('image-to-text')
|
13 |
caption = cap(image)
|
@@ -18,16 +17,18 @@ def predict(image):
|
|
18 |
senti = pipe(shortened)
|
19 |
return senti
|
20 |
caption_string = str(caption)
|
21 |
-
shortened = caption_string
|
22 |
-
|
|
|
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 =
|
28 |
return output
|
29 |
|
30 |
|
|
|
31 |
input = gr.inputs.Image(
|
32 |
label="Upload your Image and wait for 8-12 seconds!", type='pil', optional=False)
|
33 |
output = gr.outputs.Textbox(label="Captions")
|
|
|
7 |
|
8 |
|
9 |
|
|
|
10 |
def predict(image):
|
11 |
cap = pipeline('image-to-text')
|
12 |
caption = cap(image)
|
|
|
17 |
senti = pipe(shortened)
|
18 |
return senti
|
19 |
caption_string = str(caption)
|
20 |
+
shortened = caption_string[21:-3]
|
21 |
+
formatted_capt = caption_string.replace("[{'generated_text': '" , "The image is of, ")
|
22 |
+
formatted_capt = formatted_capt.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 = formatted_capt + formated_senti[0:-2] + '%'
|
28 |
return output
|
29 |
|
30 |
|
31 |
+
|
32 |
input = gr.inputs.Image(
|
33 |
label="Upload your Image and wait for 8-12 seconds!", type='pil', optional=False)
|
34 |
output = gr.outputs.Textbox(label="Captions")
|