Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -106,7 +106,7 @@ def process_vision_query(image, text_input):
|
|
106 |
response = vision_processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
107 |
return response
|
108 |
|
109 |
-
#
|
110 |
def combined_chat(message, image, history, system_prompt, temperature, max_new_tokens, top_p, top_k):
|
111 |
if image is not None:
|
112 |
# Process image query
|
@@ -117,42 +117,41 @@ def combined_chat(message, image, history, system_prompt, temperature, max_new_t
|
|
117 |
# Process text query
|
118 |
return stream_text_chat(message, history, system_prompt, temperature, max_new_tokens, top_p, top_k), None
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
# Custom CSS
|
121 |
custom_css = """
|
122 |
-
body { background-color: #
|
123 |
-
|
124 |
-
#
|
125 |
-
#
|
126 |
-
#
|
127 |
-
#
|
128 |
-
|
129 |
-
#component-0, #component-1, #component-2 { max-width: 100% !important;}
|
130 |
-
footer { text-align: center; margin-top: 2rem; color: #64748b;}
|
131 |
-
"""
|
132 |
-
|
133 |
-
# Custom HTML for the header
|
134 |
-
custom_header = """
|
135 |
-
<div id="custom-header">
|
136 |
-
<h1><span class="blue">Phi 3.5</span> <span class="pink">Multimodal Assistant</span></h1>
|
137 |
-
<h2>Text and Vision AI at Your Service</h2>
|
138 |
-
</div>
|
139 |
"""
|
140 |
|
141 |
# Gradio interface
|
142 |
-
with gr.Blocks(css=custom_css, theme=gr.themes.
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
156 |
|
157 |
with gr.Accordion("Advanced Options", open=False):
|
158 |
system_prompt = gr.Textbox(value="You are a helpful assistant", label="System Prompt")
|
@@ -160,12 +159,10 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base().set(
|
|
160 |
max_new_tokens = gr.Slider(minimum=128, maximum=8192, step=1, value=1024, label="Max new tokens")
|
161 |
top_p = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=1.0, label="top_p")
|
162 |
top_k = gr.Slider(minimum=1, maximum=20, step=1, value=20, label="top_k")
|
163 |
-
|
164 |
-
submit_btn = gr.Button("Submit", variant="primary")
|
165 |
-
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
166 |
|
167 |
-
|
168 |
-
|
|
|
169 |
|
170 |
gr.HTML("<footer>Powered by Phi 3.5 Multimodal AI</footer>")
|
171 |
|
|
|
106 |
response = vision_processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
107 |
return response
|
108 |
|
109 |
+
# Modified combined chat function
|
110 |
def combined_chat(message, image, history, system_prompt, temperature, max_new_tokens, top_p, top_k):
|
111 |
if image is not None:
|
112 |
# Process image query
|
|
|
117 |
# Process text query
|
118 |
return stream_text_chat(message, history, system_prompt, temperature, max_new_tokens, top_p, top_k), None
|
119 |
|
120 |
+
# Function to toggle between text and image input
|
121 |
+
def toggle_input(choice):
|
122 |
+
if choice == "Text":
|
123 |
+
return gr.update(visible=True), gr.update(visible=False)
|
124 |
+
else:
|
125 |
+
return gr.update(visible=False), gr.update(visible=True)
|
126 |
+
|
127 |
# Custom CSS
|
128 |
custom_css = """
|
129 |
+
body { background-color: #343541; color: #ececf1; font-family: 'Arial', sans-serif; }
|
130 |
+
.gradio-container { max-width: 800px !important; margin: auto; }
|
131 |
+
#chatbot { height: 400px; overflow-y: auto; }
|
132 |
+
#input-container { display: flex; align-items: center; }
|
133 |
+
#msg, #image-input { flex-grow: 1; margin-right: 10px; }
|
134 |
+
#submit-btn { min-width: 60px; }
|
135 |
+
footer { text-align: center; margin-top: 2rem; color: #acacbe; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
"""
|
137 |
|
138 |
# Gradio interface
|
139 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
140 |
+
chatbot = gr.Chatbot(elem_id="chatbot")
|
141 |
+
|
142 |
+
with gr.Row(elem_id="input-container"):
|
143 |
+
input_type = gr.Radio(["Text", "Image"], value="Text", label="Input Type")
|
144 |
+
with gr.Column(visible=True) as text_input:
|
145 |
+
msg = gr.Textbox(
|
146 |
+
show_label=False,
|
147 |
+
placeholder="Send a message...",
|
148 |
+
elem_id="msg"
|
149 |
+
)
|
150 |
+
with gr.Column(visible=False) as image_input:
|
151 |
+
image = gr.Image(type="pil", elem_id="image-input")
|
152 |
+
|
153 |
+
submit_btn = gr.Button("Send", elem_id="submit-btn")
|
154 |
+
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
155 |
|
156 |
with gr.Accordion("Advanced Options", open=False):
|
157 |
system_prompt = gr.Textbox(value="You are a helpful assistant", label="System Prompt")
|
|
|
159 |
max_new_tokens = gr.Slider(minimum=128, maximum=8192, step=1, value=1024, label="Max new tokens")
|
160 |
top_p = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=1.0, label="top_p")
|
161 |
top_k = gr.Slider(minimum=1, maximum=20, step=1, value=20, label="top_k")
|
|
|
|
|
|
|
162 |
|
163 |
+
input_type.change(toggle_input, input_type, [text_input, image_input])
|
164 |
+
submit_btn.click(combined_chat, [msg, image, chatbot, system_prompt, temperature, max_new_tokens, top_p, top_k], [chatbot, image])
|
165 |
+
clear_btn.click(lambda: ([], None), None, [chatbot, image], queue=False)
|
166 |
|
167 |
gr.HTML("<footer>Powered by Phi 3.5 Multimodal AI</footer>")
|
168 |
|