Spaces:
Sleeping
Sleeping
File size: 2,008 Bytes
62597bd 3355085 fd50f79 3355085 fd50f79 3355085 fd50f79 3355085 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import streamlit as st
from transformers import pipeline
from PIL import Image
st.title("Multimodal AI App π€")
st.sidebar.header("π§ Choose Task")
task = st.sidebar.selectbox("π Select task", ["πΌοΈ Visual Question Answering", "π Translate to Urdu", "π Story Generator"])
if task == "πΌοΈ Visual Question Answering":
st.header("πΌοΈ Visual Question Answering")
uploaded_file = st.file_uploader("π€ Upload an image", type=["jpg", "png", "jpeg"])
question = st.text_input("β Ask a question about the image")
if uploaded_file and question:
image = Image.open(uploaded_file)
if st.button("π Ask Question"):
with st.spinner('β³ Loading VQA model...'):
vqa_pipe = pipeline("visual-question-answering", model="dandelin/vilt-b32-finetuned-vqa")
result = vqa_pipe(image, question)
st.image(image, caption="πΌοΈ Uploaded Image")
st.success(f"β
**Answer:** {result[0]['answer']}")
elif task == "π Translate to Urdu":
st.header("π English to Urdu Translation")
input_text = st.text_area("βοΈ Enter English text")
if st.button("π Translate"):
with st.spinner('β³ Loading Translation model...'):
translator = pipeline("translation", model="facebook/nllb-200-distilled-600M")
translation = translator(input_text, src_lang="eng_Latn", tgt_lang="urd_Arab")
st.success(f"β
**Urdu Translation:** {translation[0]['translation_text']}")
elif task == "π Story Generator":
st.header("π Story Generator")
prompt = st.text_input("π‘ Enter a prompt")
if st.button("βοΈ Generate Story"):
with st.spinner('β³ Loading Text Generation model...'):
text_gen_pipe = pipeline("text-generation", model="openai-community/gpt2")
result = text_gen_pipe(prompt, max_length=100, num_return_sequences=1)
st.success(f"β
**Generated Text:** {result[0]['generated_text']}")
|