File size: 926 Bytes
f2adea7
a8daede
 
f2adea7
94691cf
b5e04f5
94691cf
b5e04f5
 
 
 
 
 
94691cf
b5e04f5
 
 
 
94691cf
b5e04f5
 
 
 
94691cf
b5e04f5
94691cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()