Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +34 -38
src/streamlit_app.py
CHANGED
|
@@ -2,45 +2,41 @@ import streamlit as st
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
-
|
| 6 |
-
st.title("
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
task = st.sidebar.radio("Choose a Task", ["Text Generation", "Visual QA", "Text Summarization"])
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
st.
|
| 14 |
-
|
| 15 |
-
if
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
# ----------------- VISUAL QUESTION ANSWERING -----------------
|
| 23 |
-
elif task == "Visual QA":
|
| 24 |
-
st.subheader("πΌοΈ Visual Question Answering")
|
| 25 |
-
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 26 |
-
question = st.text_input("Ask a question about the image", "What colors are used in this image?")
|
| 27 |
-
|
| 28 |
-
if uploaded_image and question:
|
| 29 |
-
image = Image.open(uploaded_image)
|
| 30 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 31 |
-
if st.button("Get Answer"):
|
| 32 |
-
with st.spinner("Answering..."):
|
| 33 |
-
vqa = pipeline("visual-question-answering", model="dandelin/vilt-b32-finetuned-vqa")
|
| 34 |
-
result = vqa(image, question)
|
| 35 |
-
st.success(f"Answer: {result[0]['answer']}")
|
| 36 |
|
| 37 |
-
# ----------------- TEXT SUMMARIZATION -----------------
|
| 38 |
-
elif task == "Text Summarization":
|
| 39 |
-
st.subheader("π Text Summarization")
|
| 40 |
-
input_text = st.text_area("Paste long text here", height=200)
|
| 41 |
-
if st.button("Summarize"):
|
| 42 |
-
with st.spinner("Summarizing..."):
|
| 43 |
-
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
| 44 |
-
summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
|
| 45 |
-
st.success("Summary:")
|
| 46 |
-
st.write(summary[0]['summary_text'])
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
+
|
| 6 |
+
st.title("Multimodal AI App π€")
|
| 7 |
+
st.sidebar.header("π§ Choose Task")
|
| 8 |
|
| 9 |
+
task = st.sidebar.selectbox("π Select task", ["πΌοΈ Visual Question Answering", "π Translate to Urdu", "π Story Generator"])
|
|
|
|
| 10 |
|
| 11 |
+
if task == "πΌοΈ Visual Question Answering":
|
| 12 |
+
st.header("πΌοΈ Visual Question Answering")
|
| 13 |
+
uploaded_file = st.file_uploader("π€ Upload an image", type=["jpg", "png", "jpeg"])
|
| 14 |
+
question = st.text_input("β Ask a question about the image")
|
| 15 |
+
if uploaded_file and question:
|
| 16 |
+
image = Image.open(uploaded_file)
|
| 17 |
+
if st.button("π Ask Question"):
|
| 18 |
+
with st.spinner('β³ Loading VQA model...'):
|
| 19 |
+
vqa_pipe = pipeline("visual-question-answering", model="dandelin/vilt-b32-finetuned-vqa")
|
| 20 |
+
result = vqa_pipe(image, question)
|
| 21 |
+
st.image(image, caption="πΌοΈ Uploaded Image")
|
| 22 |
+
st.success(f"β
**Answer:** {result[0]['answer']}")
|
| 23 |
+
|
| 24 |
+
elif task == "π Translate to Urdu":
|
| 25 |
+
st.header("π English to Urdu Translation")
|
| 26 |
+
input_text = st.text_area("βοΈ Enter English text")
|
| 27 |
+
if st.button("π Translate"):
|
| 28 |
+
with st.spinner('β³ Loading Translation model...'):
|
| 29 |
+
translator = pipeline("translation", model="facebook/nllb-200-distilled-600M")
|
| 30 |
+
translation = translator(input_text, src_lang="eng_Latn", tgt_lang="urd_Arab")
|
| 31 |
+
st.success(f"β
**Urdu Translation:** {translation[0]['translation_text']}")
|
| 32 |
+
|
| 33 |
+
elif task == "π Story Generator":
|
| 34 |
+
st.header("π Story Generator")
|
| 35 |
+
prompt = st.text_input("π‘ Enter a prompt")
|
| 36 |
+
if st.button("βοΈ Generate Story"):
|
| 37 |
+
with st.spinner('β³ Loading Text Generation model...'):
|
| 38 |
+
text_gen_pipe = pipeline("text-generation", model="openai-community/gpt2")
|
| 39 |
+
result = text_gen_pipe(prompt, max_length=100, num_return_sequences=1)
|
| 40 |
+
st.success(f"β
**Generated Text:** {result[0]['generated_text']}")
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|