Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,21 +11,21 @@ multimodal_phi2 = MultiModalPhi2(
|
|
11 |
device="cpu",
|
12 |
)
|
13 |
|
14 |
-
def add_content(chatbot,
|
15 |
textflag, imageflag, audioflag = False, False, False
|
16 |
-
if
|
17 |
chatbot.append((text, None))
|
18 |
textflag = True
|
19 |
-
if
|
20 |
chatbot.append(((image,), None))
|
21 |
imageflag = True
|
22 |
-
if
|
23 |
chatbot.append(((audio_mic,), None))
|
24 |
audioflag = True
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
if not any([textflag, imageflag, audioflag]):
|
30 |
# Raise an error if neither text nor file is provided
|
31 |
raise gr.Error("Enter a valid text, image or audio")
|
@@ -61,31 +61,54 @@ def run(history, text, image, audio_upload, audio_mic):
|
|
61 |
|
62 |
|
63 |
with gr.Blocks() as demo:
|
64 |
-
|
65 |
-
[],
|
66 |
-
elem_id="chatbot",
|
67 |
-
bubble_full_width=False,
|
68 |
-
avatar_images=(None, (os.path.join(os.path.dirname(__file__), "avatar.png"))),
|
69 |
-
)
|
70 |
|
71 |
with gr.Row():
|
72 |
-
|
73 |
-
scale
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
)
|
83 |
-
img_audio_msg = img_audio.upload(add_input, [chatbot, img_audio], [chatbot, "image"], queue=False).then(
|
84 |
-
bot, chatbot, chatbot
|
85 |
-
)
|
86 |
-
|
87 |
-
# chatbot.like(print_like_dislike, None, None)
|
88 |
|
|
|
|
|
|
|
|
|
89 |
|
90 |
-
|
91 |
-
demo.launch()
|
|
|
11 |
device="cpu",
|
12 |
)
|
13 |
|
14 |
+
def add_content(chatbot, text, image, audio_upload, audio_mic) -> gr.Chatbot:
|
15 |
textflag, imageflag, audioflag = False, False, False
|
16 |
+
if text not in ["", None]:
|
17 |
chatbot.append((text, None))
|
18 |
textflag = True
|
19 |
+
if image is not None:
|
20 |
chatbot.append(((image,), None))
|
21 |
imageflag = True
|
22 |
+
if audio_mic is not None:
|
23 |
chatbot.append(((audio_mic,), None))
|
24 |
audioflag = True
|
25 |
+
else:
|
26 |
+
if audio_upload is not None:
|
27 |
+
chatbot.append(((audio_upload,), None))
|
28 |
+
audioflag = True
|
29 |
if not any([textflag, imageflag, audioflag]):
|
30 |
# Raise an error if neither text nor file is provided
|
31 |
raise gr.Error("Enter a valid text, image or audio")
|
|
|
61 |
|
62 |
|
63 |
with gr.Blocks() as demo:
|
64 |
+
gr.Markdown("## MulitModal Phi2 Model Pretraining and Finetuning from Scratch")
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
with gr.Row():
|
67 |
+
with gr.Column(scale=4):
|
68 |
+
# Creating a column with a scale of 6
|
69 |
+
with gr.Box():
|
70 |
+
with gr.Row():
|
71 |
+
# Adding a Textbox with a placeholder "write prompt"
|
72 |
+
prompt = gr.Textbox(
|
73 |
+
placeholder="Enter Prompt", lines=2, label="Query", value=None
|
74 |
+
)
|
75 |
+
# Creating a column with a scale of 2
|
76 |
+
with gr.Row():
|
77 |
+
# Adding image
|
78 |
+
image = gr.UploadButton("π", file_types=["image"], label="Upload Image")
|
79 |
+
# Creating a column with a scale of 2
|
80 |
+
with gr.Row():
|
81 |
+
# Add audio
|
82 |
+
audio_upload = gr.UploadButton("π", file_types=["audio"], label="Upload Audio")
|
83 |
+
audio_mic = gr.Audio(
|
84 |
+
source="microphone", type="filepath", format="mp3"
|
85 |
+
)
|
86 |
+
|
87 |
+
with gr.Column(scale=8):
|
88 |
+
with gr.Box():
|
89 |
+
with gr.Row():
|
90 |
+
chatbot = gr.Chatbot(
|
91 |
+
avatar_images=("π§", "π€"),
|
92 |
+
height=550,
|
93 |
+
)
|
94 |
+
with gr.Row():
|
95 |
+
# Adding a Button
|
96 |
+
submit = gr.Button()
|
97 |
+
clear = gr.Button(value="Clear")
|
98 |
+
|
99 |
+
submit.click(
|
100 |
+
add_content,
|
101 |
+
inputs=[chatbot, prompt, image, audio_upload, audio_mic],
|
102 |
+
outputs=[chatbot],
|
103 |
+
).success(
|
104 |
+
run,
|
105 |
+
inputs=[chatbot, prompt, image, audio_upload, audio_mic],
|
106 |
+
outputs=[chatbot, prompt, image, audio_upload, audio_mic],
|
107 |
)
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
+
clear.click(
|
110 |
+
clear_data,
|
111 |
+
outputs=[prompt, image, audio_upload, audio_mic, chatbot],
|
112 |
+
)
|
113 |
|
114 |
+
demo.launch()
|
|