Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
chat_model = pipeline("text-generation", model="Qwen/Qwen-1.5-0.5B-Chat", device=-1)
|
| 6 |
caption_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base", device=-1)
|
| 7 |
speech_model = pipeline("automatic-speech-recognition", model="openai/whisper-tiny", device=-1)
|
| 8 |
|
| 9 |
-
#
|
| 10 |
def process_text(user_input):
|
| 11 |
result = chat_model(user_input, max_new_tokens=128, do_sample=True, temperature=0.7)
|
| 12 |
return result[0]["generated_text"]
|
|
@@ -18,51 +18,44 @@ def process_image(image):
|
|
| 18 |
def process_audio(audio_path):
|
| 19 |
transcript = speech_model(audio_path)["text"]
|
| 20 |
reply = process_text(transcript)
|
| 21 |
-
return f"๐ค You said: **{transcript}**\n\n๐ค Assistant
|
| 22 |
|
| 23 |
-
# --- Redesigned Gradio App ---
|
| 24 |
with gr.Blocks(theme="soft", css="""
|
| 25 |
body {
|
| 26 |
-
background: linear-gradient(135deg, #
|
| 27 |
-
font-family: '
|
| 28 |
}
|
| 29 |
-
#
|
| 30 |
""") as demo:
|
| 31 |
|
| 32 |
-
gr.HTML("<h1 style='text-align:center; color:white;'>โจ AssistAI
|
| 33 |
-
gr.Markdown("
|
| 34 |
|
| 35 |
with gr.Tab("๐ฌ Chat Genie"):
|
| 36 |
-
gr.
|
| 37 |
-
|
| 38 |
-
txt_out = gr.Textbox(label="Genie
|
| 39 |
examples = gr.Examples(
|
| 40 |
-
examples=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
inputs=[txt_in]
|
| 42 |
)
|
| 43 |
-
|
| 44 |
|
| 45 |
with gr.Tab("๐ผ๏ธ Image Magic"):
|
| 46 |
-
gr.
|
| 47 |
-
|
| 48 |
img_out = gr.Textbox(label="AI's magical description โจ", lines=5)
|
| 49 |
-
|
| 50 |
|
| 51 |
with gr.Tab("๐ค Voice Spell"):
|
| 52 |
-
gr.
|
| 53 |
-
|
| 54 |
-
aud_out = gr.Textbox(label="
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
gr.Markdown("Some magic tricks to try instantly ๐")
|
| 59 |
-
demo_examples = gr.Dataset(components=[gr.Textbox()], samples=[
|
| 60 |
-
["Write a pirate poem about coding โต๐ป"],
|
| 61 |
-
["Tell me a joke about AI ๐ค๐"],
|
| 62 |
-
["Explain infinity to a 5-year-old ๐งธโจ"]
|
| 63 |
-
])
|
| 64 |
-
demo_out = gr.Textbox(label="AI Outputs", lines=7)
|
| 65 |
-
demo_examples.click(process_text, inputs=demo_examples, outputs=demo_out)
|
| 66 |
-
|
| 67 |
-
if __name__ == "__main__":
|
| 68 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Pipelines (same as before, unchanged)
|
| 5 |
chat_model = pipeline("text-generation", model="Qwen/Qwen-1.5-0.5B-Chat", device=-1)
|
| 6 |
caption_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base", device=-1)
|
| 7 |
speech_model = pipeline("automatic-speech-recognition", model="openai/whisper-tiny", device=-1)
|
| 8 |
|
| 9 |
+
# Functions (all safe and previously working)
|
| 10 |
def process_text(user_input):
|
| 11 |
result = chat_model(user_input, max_new_tokens=128, do_sample=True, temperature=0.7)
|
| 12 |
return result[0]["generated_text"]
|
|
|
|
| 18 |
def process_audio(audio_path):
|
| 19 |
transcript = speech_model(audio_path)["text"]
|
| 20 |
reply = process_text(transcript)
|
| 21 |
+
return f"๐ค You said: **{transcript}**\n\n๐ค Assistant: {reply}"
|
| 22 |
|
|
|
|
| 23 |
with gr.Blocks(theme="soft", css="""
|
| 24 |
body {
|
| 25 |
+
background: linear-gradient(135deg, #ff9a9e, #fad0c4 30%, #fad0c4 70%, #fbc2eb);
|
| 26 |
+
font-family: 'Comic Sans MS', cursive;
|
| 27 |
}
|
| 28 |
+
#chatbox {height:200px}
|
| 29 |
""") as demo:
|
| 30 |
|
| 31 |
+
gr.HTML("<h1 style='text-align:center; color:white;'>๐โจ AssistAI โ Your Magical Multimodal Buddy โจ๐</h1>")
|
| 32 |
+
gr.Markdown("Welcome! Try text, images, or your voice and see the magic ๐งโโ๏ธ\n---")
|
| 33 |
|
| 34 |
with gr.Tab("๐ฌ Chat Genie"):
|
| 35 |
+
txt_in = gr.Textbox(label="Ask me anything ๐ง", lines=3, placeholder="E.g. Tell me a riddle", elem_id="chatbox")
|
| 36 |
+
btn_chat = gr.Button("โจ Generate Reply โจ")
|
| 37 |
+
txt_out = gr.Textbox(label="Genie Responds", lines=8)
|
| 38 |
examples = gr.Examples(
|
| 39 |
+
examples=[
|
| 40 |
+
"Tell me a riddle",
|
| 41 |
+
"Summarize Harry Potter in one sentence",
|
| 42 |
+
"What's faster: a cheetah or WiFi?",
|
| 43 |
+
"Write me a pirate poem about coding โต๐ป"
|
| 44 |
+
],
|
| 45 |
inputs=[txt_in]
|
| 46 |
)
|
| 47 |
+
btn_chat.click(process_text, inputs=txt_in, outputs=txt_out)
|
| 48 |
|
| 49 |
with gr.Tab("๐ผ๏ธ Image Magic"):
|
| 50 |
+
img_in = gr.Image(type="pil", label="Upload image ๐ผ๏ธ")
|
| 51 |
+
btn_img = gr.Button("๐ช Generate Caption")
|
| 52 |
img_out = gr.Textbox(label="AI's magical description โจ", lines=5)
|
| 53 |
+
btn_img.click(process_image, inputs=img_in, outputs=img_out)
|
| 54 |
|
| 55 |
with gr.Tab("๐ค Voice Spell"):
|
| 56 |
+
aud_in = gr.Audio(sources=["microphone"], type="filepath", label="Speak your spell ๐ค")
|
| 57 |
+
btn_voice = gr.Button("๐ฎ Transcribe + Reply")
|
| 58 |
+
aud_out = gr.Textbox(label="Transcript + Genie reply", lines=7)
|
| 59 |
+
btn_voice.click(process_audio, inputs=aud_in, outputs=aud_out)
|
| 60 |
|
| 61 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|