sentiment / app.py
ThuggingT's picture
Update app.py
b5e04f5 verified
from transformers import pipeline
import gradio as gr
sentiment = pipeline('sentiment-analysis')
en_to_fr = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
img_to_text = pipeline(model="ydshieh/vit-gpt2-coco-en")
with gr.Blocks() as demo:
with gr.Tab("Sentiment"):
txt = gr.Textbox(label="Type your review", lines=2,
placeholder="e.g. good place with great food")
out1 = gr.Label()
txt.submit(lambda t: sentiment(t)[0], inputs=txt, outputs=out1)
with gr.Tab("Translation"):
txt2 = gr.Textbox(label="Type text to translate", lines=2)
out2 = gr.Textbox()
txt2.submit(lambda t: en_to_fr(t)[0]['translation_text'], inputs=txt2, outputs=out2)
with gr.Tab("Image → Text"):
img = gr.Image(type="pil")
out3 = gr.Textbox()
img.change(lambda i: img_to_text(i)[0]['generated_text'], img, out3)
demo.launch()