Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
import warnings | |
import logging | |
warnings.simplefilter('ignore') | |
logging.disable(logging.WARNING) | |
def predict(image): | |
cap = pipeline('image-to-text') | |
caption = cap(image) | |
def sentiment_analysis(shortened): | |
pipe = pipeline('sentiment-analysis') | |
senti = pipe(shortened) | |
return senti | |
caption_string = str(caption) | |
sentiment = sentiment_analysis(caption_string[21:-1]) | |
sentiment_string = ''.join(str(e) for e in sentiment) | |
image_caption = caption_string[21:-3] | |
percentage =sentiment_string[34: -14] | |
tone = sentiment_string[11:-31] | |
output = 'the image is of, ' + image_caption + ", the overall tone of the image's content is - "+ tone + " with a approx "+ percentage + "% score" | |
return output | |
input = gr.inputs.Image( | |
label="Upload your Image and wait for 8-12 seconds!", type='pil', optional=False) | |
output = gr.outputs.Textbox(label="Captions") | |
title = "Content-Mod API with Sentiment-Analysis UI " | |
interface = gr.Interface( | |
fn=predict, | |
inputs=input, | |
outputs=output, | |
title=title, | |
) | |
interface.launch() | |