Spaces:
Sleeping
Sleeping
# prompt: currently the image generation function starts after user give a single letter. but for user friendly reason it should start to process after user gives his entrie input. here generate button is big make it small | |
from transformers import pipeline | |
import gradio as gr | |
from diffusers import DiffusionPipeline | |
import torch | |
import time | |
# Load models | |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-dra-en") | |
summarizer = pipeline("summarization", model="Falconsai/text_summarization") | |
image_pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to("cuda") | |
# Translate Tamil to English | |
def translate_tamil_to_english(text): | |
time.sleep(2) | |
result = translator(text) | |
return result[0]['translation_text'] | |
# Summarize English Paragraph | |
def summarize_english_text(paragraph): | |
time.sleep(2) | |
summary = summarizer(paragraph, max_length=100, min_length=25, do_sample=False) | |
return summary[0]['summary_text'] | |
# Generate image from English text | |
def english_text_to_image(text): | |
image = image_pipe(text).images[0] | |
return image | |
with gr.Blocks() as app: | |
gr.Markdown("# Multifunctional Gradio App") | |
with gr.Row(): | |
tamil_input = gr.Textbox(lines=2, placeholder="Enter Tamil text here...") | |
english_output = gr.Textbox(label="English Translation") | |
translate_button = gr.Button("Translate") | |
translate_button.click(translate_tamil_to_english, inputs=tamil_input, outputs=english_output) | |
with gr.Row(): | |
english_paragraph_input = gr.Textbox(lines=5, placeholder="Enter English paragraph here...") | |
summary_output = gr.Textbox(label="Summary") | |
summarize_button = gr.Button("Summarize") | |
summarize_button.click(summarize_english_text, inputs=english_paragraph_input, outputs=summary_output) | |
with gr.Row(): | |
english_text_input = gr.Textbox(lines=2, placeholder="Enter English text for image generation...") | |
image_output = gr.Image(label="Generated Image") | |
generate_button = gr.Button("Generate Image", size="sm") # Make the button smaller | |
generate_button.click(english_text_to_image, inputs=english_text_input, outputs=image_output) | |
app.launch() | |