|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
translation_pipeline = pipeline("translation", model="Helsinki-NLP/opus-mt-ta-en") |
|
text_generation_pipeline = pipeline("text-generation", model="gpt2") |
|
|
|
|
|
def generate_image(prompt: str) -> str: |
|
|
|
return f"https://via.placeholder.com/512?text={prompt.replace(' ', '+')}" |
|
|
|
|
|
def multimodal_pipeline(tamil_text: str): |
|
|
|
translated = translation_pipeline(tamil_text)[0]["translation_text"] |
|
|
|
|
|
generated = text_generation_pipeline(translated, max_length=50, do_sample=True)[0]["generated_text"] |
|
|
|
|
|
image_url = generate_image(generated) |
|
|
|
return translated, generated, image_url |
|
|
|
|
|
interface = gr.Interface( |
|
fn=multimodal_pipeline, |
|
inputs=gr.Textbox(label="Enter Tamil Text", placeholder="உங்கள் தமிழ் உரையை இங்கே உள்ளிடவும்"), |
|
outputs=[ |
|
gr.Textbox(label="English Translation"), |
|
gr.Textbox(label="Generated Prompt"), |
|
gr.Image(label="Generated Image"), |
|
], |
|
title="Tamil to Image Multimodal App", |
|
description="This app translates Tamil to English, generates a descriptive sentence, and creates an image based on it." |
|
) |
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|