Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -97,14 +97,69 @@ def process_vision_query(image, text_input):
|
|
97 |
response = vision_processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
98 |
return response
|
99 |
|
100 |
-
#
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
with gr.Tab("Text Model (Phi-3.5-mini)"):
|
106 |
-
chatbot = gr.Chatbot(height=
|
107 |
-
msg = gr.Textbox(label="Message")
|
108 |
with gr.Accordion("Advanced Options", open=False):
|
109 |
system_prompt = gr.Textbox(value="You are a helpful assistant", label="System Prompt")
|
110 |
temperature = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.8, label="Temperature")
|
@@ -112,22 +167,24 @@ with gr.Blocks() as demo:
|
|
112 |
top_p = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=1.0, label="top_p")
|
113 |
top_k = gr.Slider(minimum=1, maximum=20, step=1, value=20, label="top_k")
|
114 |
|
115 |
-
submit_btn = gr.Button("Submit")
|
116 |
-
clear_btn = gr.Button("Clear")
|
117 |
|
118 |
submit_btn.click(stream_text_chat, [msg, chatbot, system_prompt, temperature, max_new_tokens, top_p, top_k], [chatbot])
|
119 |
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
120 |
|
121 |
with gr.Tab("Vision Model (Phi-3.5-vision)"):
|
122 |
with gr.Row():
|
123 |
-
with gr.Column():
|
124 |
-
vision_input_img = gr.Image(label="
|
125 |
-
vision_text_input = gr.Textbox(label="
|
126 |
-
vision_submit_btn = gr.Button(
|
127 |
-
with gr.Column():
|
128 |
-
vision_output_text = gr.Textbox(label="
|
129 |
|
130 |
vision_submit_btn.click(process_vision_query, [vision_input_img, vision_text_input], [vision_output_text])
|
131 |
|
|
|
|
|
132 |
if __name__ == "__main__":
|
133 |
demo.launch()
|
|
|
97 |
response = vision_processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
98 |
return response
|
99 |
|
100 |
+
# Custom CSS
|
101 |
+
custom_css = """
|
102 |
+
body { background-color: #0b0f19; color: #e2e8f0; font-family: 'Arial', sans-serif;}
|
103 |
+
#custom-header { text-align: center; padding: 20px 0; background-color: #1a202c; margin-bottom: 20px; border-radius: 10px;}
|
104 |
+
#custom-header h1 { font-size: 2.5rem; margin-bottom: 0.5rem;}
|
105 |
+
#custom-header h1 .blue { color: #60a5fa;}
|
106 |
+
#custom-header h1 .pink { color: #f472b6;}
|
107 |
+
#custom-header h2 { font-size: 1.5rem; color: #94a3b8;}
|
108 |
+
.suggestions { display: flex; justify-content: center; flex-wrap: wrap; gap: 1rem; margin: 20px 0;}
|
109 |
+
.suggestion { background-color: #1e293b; border-radius: 0.5rem; padding: 1rem; display: flex; align-items: center; transition: transform 0.3s ease; width: 200px;}
|
110 |
+
.suggestion:hover { transform: translateY(-5px);}
|
111 |
+
.suggestion-icon { font-size: 1.5rem; margin-right: 1rem; background-color: #2d3748; padding: 0.5rem; border-radius: 50%;}
|
112 |
+
.gradio-container { max-width: 100% !important;}
|
113 |
+
#component-0, #component-1, #component-2 { max-width: 100% !important;}
|
114 |
+
footer { text-align: center; margin-top: 2rem; color: #64748b;}
|
115 |
+
"""
|
116 |
+
|
117 |
+
# Custom HTML for the header
|
118 |
+
custom_header = """
|
119 |
+
<div id="custom-header">
|
120 |
+
<h1><span class="blue">Phi 3.5</span> <span class="pink">Multimodal Assistant</span></h1>
|
121 |
+
<h2>Text and Vision AI at Your Service</h2>
|
122 |
+
</div>
|
123 |
+
"""
|
124 |
+
|
125 |
+
# Custom HTML for suggestions
|
126 |
+
custom_suggestions = """
|
127 |
+
<div class="suggestions">
|
128 |
+
<div class="suggestion">
|
129 |
+
<span class="suggestion-icon">💬</span>
|
130 |
+
<p>Chat with the Text Model</p>
|
131 |
+
</div>
|
132 |
+
<div class="suggestion">
|
133 |
+
<span class="suggestion-icon">🖼️</span>
|
134 |
+
<p>Analyze Images with Vision Model</p>
|
135 |
+
</div>
|
136 |
+
<div class="suggestion">
|
137 |
+
<span class="suggestion-icon">🤖</span>
|
138 |
+
<p>Get AI-generated responses</p>
|
139 |
+
</div>
|
140 |
+
<div class="suggestion">
|
141 |
+
<span class="suggestion-icon">🔍</span>
|
142 |
+
<p>Explore advanced options</p>
|
143 |
+
</div>
|
144 |
+
</div>
|
145 |
+
"""
|
146 |
+
|
147 |
+
# Gradio interface
|
148 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Base().set(
|
149 |
+
body_background_fill="#0b0f19",
|
150 |
+
body_text_color="#e2e8f0",
|
151 |
+
button_primary_background_fill="#3b82f6",
|
152 |
+
button_primary_background_fill_hover="#2563eb",
|
153 |
+
button_primary_text_color="white",
|
154 |
+
block_title_text_color="#94a3b8",
|
155 |
+
block_label_text_color="#94a3b8",
|
156 |
+
)) as demo:
|
157 |
+
gr.HTML(custom_header)
|
158 |
+
gr.HTML(custom_suggestions)
|
159 |
|
160 |
with gr.Tab("Text Model (Phi-3.5-mini)"):
|
161 |
+
chatbot = gr.Chatbot(height=400)
|
162 |
+
msg = gr.Textbox(label="Message", placeholder="Type your message here...")
|
163 |
with gr.Accordion("Advanced Options", open=False):
|
164 |
system_prompt = gr.Textbox(value="You are a helpful assistant", label="System Prompt")
|
165 |
temperature = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.8, label="Temperature")
|
|
|
167 |
top_p = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=1.0, label="top_p")
|
168 |
top_k = gr.Slider(minimum=1, maximum=20, step=1, value=20, label="top_k")
|
169 |
|
170 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
171 |
+
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
172 |
|
173 |
submit_btn.click(stream_text_chat, [msg, chatbot, system_prompt, temperature, max_new_tokens, top_p, top_k], [chatbot])
|
174 |
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
175 |
|
176 |
with gr.Tab("Vision Model (Phi-3.5-vision)"):
|
177 |
with gr.Row():
|
178 |
+
with gr.Column(scale=1):
|
179 |
+
vision_input_img = gr.Image(label="Upload an Image", type="pil")
|
180 |
+
vision_text_input = gr.Textbox(label="Ask a question about the image", placeholder="What do you see in this image?")
|
181 |
+
vision_submit_btn = gr.Button("Analyze Image", variant="primary")
|
182 |
+
with gr.Column(scale=1):
|
183 |
+
vision_output_text = gr.Textbox(label="AI Analysis", lines=10)
|
184 |
|
185 |
vision_submit_btn.click(process_vision_query, [vision_input_img, vision_text_input], [vision_output_text])
|
186 |
|
187 |
+
gr.HTML("<footer>Powered by Phi 3.5 Multimodal AI</footer>")
|
188 |
+
|
189 |
if __name__ == "__main__":
|
190 |
demo.launch()
|