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']}")