Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 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
|
| 2 |
+
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from diffusers import DiffusionPipeline
|
| 6 |
+
import torch
|
| 7 |
+
import time
|
| 8 |
+
|
| 9 |
+
# Load models
|
| 10 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-dra-en")
|
| 11 |
+
summarizer = pipeline("summarization", model="Falconsai/text_summarization")
|
| 12 |
+
image_pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to("cuda")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# Translate Tamil to English
|
| 16 |
+
def translate_tamil_to_english(text):
|
| 17 |
+
time.sleep(2)
|
| 18 |
+
result = translator(text)
|
| 19 |
+
return result[0]['translation_text']
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# Summarize English Paragraph
|
| 23 |
+
def summarize_english_text(paragraph):
|
| 24 |
+
time.sleep(2)
|
| 25 |
+
summary = summarizer(paragraph, max_length=100, min_length=25, do_sample=False)
|
| 26 |
+
return summary[0]['summary_text']
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Generate image from English text
|
| 30 |
+
def english_text_to_image(text):
|
| 31 |
+
image = image_pipe(text).images[0]
|
| 32 |
+
return image
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
with gr.Blocks() as app:
|
| 36 |
+
gr.Markdown("# Multifunctional Gradio App")
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
tamil_input = gr.Textbox(lines=2, placeholder="Enter Tamil text here...")
|
| 40 |
+
english_output = gr.Textbox(label="English Translation")
|
| 41 |
+
translate_button = gr.Button("Translate")
|
| 42 |
+
translate_button.click(translate_tamil_to_english, inputs=tamil_input, outputs=english_output)
|
| 43 |
+
|
| 44 |
+
with gr.Row():
|
| 45 |
+
english_paragraph_input = gr.Textbox(lines=5, placeholder="Enter English paragraph here...")
|
| 46 |
+
summary_output = gr.Textbox(label="Summary")
|
| 47 |
+
summarize_button = gr.Button("Summarize")
|
| 48 |
+
summarize_button.click(summarize_english_text, inputs=english_paragraph_input, outputs=summary_output)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
with gr.Row():
|
| 52 |
+
english_text_input = gr.Textbox(lines=2, placeholder="Enter English text for image generation...")
|
| 53 |
+
image_output = gr.Image(label="Generated Image")
|
| 54 |
+
generate_button = gr.Button("Generate Image", size="sm") # Make the button smaller
|
| 55 |
+
generate_button.click(english_text_to_image, inputs=english_text_input, outputs=image_output)
|
| 56 |
+
|
| 57 |
+
app.launch()
|