Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from diffusers import DiffusionPipeline
|
| 4 |
+
import torch
|
| 5 |
+
import time
|
| 6 |
+
|
| 7 |
+
# Load models
|
| 8 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-dra-en")
|
| 9 |
+
summarizer = pipeline("summarization", model="Falconsai/text_summarization")
|
| 10 |
+
image_pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to("cuda")
|
| 11 |
+
|
| 12 |
+
# Functions for each task
|
| 13 |
+
def translate_tamil_to_english(text):
|
| 14 |
+
time.sleep(2)
|
| 15 |
+
result = translator(text)
|
| 16 |
+
return result[0]['translation_text']
|
| 17 |
+
|
| 18 |
+
def summarize_english_text(paragraph):
|
| 19 |
+
time.sleep(2)
|
| 20 |
+
summary = summarizer(paragraph, max_length=100, min_length=25, do_sample=False)
|
| 21 |
+
return summary[0]['summary_text']
|
| 22 |
+
|
| 23 |
+
def english_text_to_image(text):
|
| 24 |
+
image = image_pipe(text).images[0]
|
| 25 |
+
return image
|
| 26 |
+
|
| 27 |
+
# Custom CSS
|
| 28 |
+
st.markdown("""
|
| 29 |
+
<style>
|
| 30 |
+
/* Background color */
|
| 31 |
+
body {
|
| 32 |
+
background-color: #f0f0f5;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/* Text color and font */
|
| 36 |
+
.stApp {
|
| 37 |
+
font-family: 'Arial', sans-serif;
|
| 38 |
+
color: #333;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/* Titles and subtitles styling */
|
| 42 |
+
h1 {
|
| 43 |
+
color: #2E8B57;
|
| 44 |
+
text-align: center;
|
| 45 |
+
text-shadow: 2px 2px 5px #aaaaaa;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
h2, h3 {
|
| 49 |
+
color: #4682B4;
|
| 50 |
+
text-shadow: 1px 1px 3px #aaaaaa;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/* Background texture */
|
| 54 |
+
.stApp {
|
| 55 |
+
background: linear-gradient(to bottom right, #fff7e6, #e6f7ff);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* Button styling */
|
| 59 |
+
button[kind="primary"] {
|
| 60 |
+
background-color: #4682B4;
|
| 61 |
+
color: white;
|
| 62 |
+
border-radius: 8px;
|
| 63 |
+
padding: 0.5rem 1rem;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
button[kind="primary"]:hover {
|
| 67 |
+
background-color: #5b9bd5;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/* Text area and input field styling */
|
| 71 |
+
textarea, input {
|
| 72 |
+
border-radius: 10px;
|
| 73 |
+
padding: 1rem;
|
| 74 |
+
border: 2px solid #ccc;
|
| 75 |
+
background-color: #f9f9f9;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/* Styling the output boxes */
|
| 79 |
+
.stMarkdown {
|
| 80 |
+
background-color: #e6f9ff;
|
| 81 |
+
padding: 1rem;
|
| 82 |
+
border-radius: 10px;
|
| 83 |
+
box-shadow: 2px 2px 10px #ccc;
|
| 84 |
+
}
|
| 85 |
+
</style>
|
| 86 |
+
""", unsafe_allow_html=True)
|
| 87 |
+
|
| 88 |
+
# Streamlit app layout
|
| 89 |
+
st.title("π Multifunctional AI Application π")
|
| 90 |
+
|
| 91 |
+
# Row 1: Tamil to English translation
|
| 92 |
+
st.subheader("π Translate Tamil to English")
|
| 93 |
+
tamil_input = st.text_area("Enter Tamil text", "")
|
| 94 |
+
if st.button("Translate"):
|
| 95 |
+
english_output = translate_tamil_to_english(tamil_input)
|
| 96 |
+
st.markdown(f"**Translated English Text**: {english_output}")
|
| 97 |
+
|
| 98 |
+
# Row 2: English paragraph summarization
|
| 99 |
+
st.subheader("π Summarize English Paragraph")
|
| 100 |
+
english_paragraph = st.text_area("Enter English paragraph", "")
|
| 101 |
+
if st.button("Summarize"):
|
| 102 |
+
summary_output = summarize_english_text(english_paragraph)
|
| 103 |
+
st.markdown(f"**Summary**: {summary_output}")
|
| 104 |
+
|
| 105 |
+
# Row 3: English text to image generation
|
| 106 |
+
st.subheader("π¨ Generate Image from English Text")
|
| 107 |
+
image_text = st.text_input("Enter description for image generation", "")
|
| 108 |
+
if st.button("Generate Image"):
|
| 109 |
+
generated_image = english_text_to_image(image_text)
|
| 110 |
+
st.image(generated_image, caption="Generated Image")
|
| 111 |
+
|