File size: 832 Bytes
34baf46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
import gradio as gr
from transformers import pipeline

# Load translation pipeline (English to French as example)
translator = pipeline("translation_en_to_fr")

# Function that takes name and image
def greet_translate_and_show(name, image):
    greeting = f"Hello, {name}!" if name else "Hello!"
    
    # Translate the greeting
    translation = translator(greeting)[0]['translation_text']
    
    return greeting, translation, image

# Interface with text and image inputs, and 3 outputs
iface = gr.Interface(
    fn=greet_translate_and_show,
    inputs=[
        gr.Text(label="Your Name"),
        gr.Image(type="pil", label="Upload an Image")
    ],
    outputs=[
        gr.Text(label="Greeting in English"),
        gr.Text(label="Translated Greeting (French)"),
        gr.Image(label="Your Image")
    ]
)

iface.launch()