nashjiwani commited on
Commit
2dbba12
ยท
verified ยท
1 Parent(s): 6a2c4b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -33
app.py CHANGED
@@ -1,12 +1,12 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # --- Pipelines (already working models, 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 ---
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 whispers: {reply}"
22
 
23
- # --- Redesigned Gradio App ---
24
  with gr.Blocks(theme="soft", css="""
25
  body {
26
- background: linear-gradient(135deg, #89f7fe, #66a6ff);
27
- font-family: 'Trebuchet MS', sans-serif;
28
  }
29
- #bigbox {height: 250px}
30
  """) as demo:
31
 
32
- gr.HTML("<h1 style='text-align:center; color:white;'>โœจ AssistAI Magic Tools โœจ</h1>")
33
- gr.Markdown("Pick a tab and enjoy some AI sorcery ๐Ÿง™โ€โ™‚๏ธ\n---")
34
 
35
  with gr.Tab("๐Ÿ’ฌ Chat Genie"):
36
- gr.Markdown("Talk with your digital genie ๐Ÿงž โ€” ask it riddles, poems, or advice!")
37
- txt_in = gr.Textbox(label="Your wish โœจ", lines=3, placeholder="Ask me anything...", elem_id="bigbox")
38
- txt_out = gr.Textbox(label="Genie responds ๐Ÿงž", lines=8)
39
  examples = gr.Examples(
40
- examples=["Tell me a riddle", "Summarize Harry Potter in one sentence", "What's faster: a cheetah or WiFi?"],
 
 
 
 
 
41
  inputs=[txt_in]
42
  )
43
- txt_in.submit(process_text, inputs=txt_in, outputs=txt_out)
44
 
45
  with gr.Tab("๐Ÿ–ผ๏ธ Image Magic"):
46
- gr.Markdown("Upload an image and let the AI describe it like a mystical mirror ๐Ÿชžโœจ")
47
- img_in = gr.Image(type="pil", label="Drop your image here ๐Ÿ“ธ")
48
  img_out = gr.Textbox(label="AI's magical description โœจ", lines=5)
49
- img_in.upload(process_image, inputs=img_in, outputs=img_out)
50
 
51
  with gr.Tab("๐ŸŽค Voice Spell"):
52
- gr.Markdown("Cast a voice spell! Speak something and see it transcribed ๐Ÿช„")
53
- aud_in = gr.Audio(sources=["microphone"], type="filepath", label="Click and speak into the mic ๐ŸŽ™๏ธ")
54
- aud_out = gr.Textbox(label="Transcription + Genie reply", lines=7)
55
- aud_in.change(process_audio, inputs=aud_in, outputs=aud_out)
56
 
57
- with gr.Tab("๐ŸŽฒ Fun Extras"):
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()