Spaces:
Running
Running
Update UI
Browse files
app.py
CHANGED
@@ -34,7 +34,6 @@ example_prompts = [
|
|
34 |
"I have $20,000 in my savings account, where I receive a 4% profit per year and payments twice a year. Can you please tell me how long it will take for me to become a millionaire?",
|
35 |
"I have total $500 create a plan with travel and food",
|
36 |
"I have $1000 and 5 years. Is it better to invest in a stock paying $15 quarterly dividends or in a 5% annual savings account?"
|
37 |
-
|
38 |
]
|
39 |
|
40 |
def get_azure_response(message, chat_history, temperature, max_tokens, top_p):
|
@@ -76,7 +75,7 @@ def get_azure_response(message, chat_history, temperature, max_tokens, top_p):
|
|
76 |
# CSS for custom styling
|
77 |
custom_css = """
|
78 |
.container {
|
79 |
-
max-width:
|
80 |
margin-left: auto !important;
|
81 |
margin-right: auto !important;
|
82 |
padding-top: 0rem !important;
|
@@ -108,11 +107,9 @@ custom_css = """
|
|
108 |
cursor: pointer !important;
|
109 |
transition: transform 0.2s !important;
|
110 |
}
|
111 |
-
|
112 |
.emoji-button:hover {
|
113 |
transform: scale(1.2) !important;
|
114 |
}
|
115 |
-
|
116 |
.message-input {
|
117 |
margin-top: 1rem !important;
|
118 |
display: flex !important;
|
@@ -128,13 +125,16 @@ custom_css = """
|
|
128 |
background-color: #f8f9fa !important;
|
129 |
padding: 1rem !important;
|
130 |
border-radius: 8px !important;
|
131 |
-
margin-
|
132 |
}
|
133 |
.examples-section {
|
134 |
background-color: #e8f4f8 !important;
|
135 |
padding: 1rem !important;
|
136 |
border-radius: 8px !important;
|
137 |
-
margin-
|
|
|
|
|
|
|
138 |
}
|
139 |
"""
|
140 |
|
@@ -145,44 +145,47 @@ with gr.Blocks(css=custom_css, title="Phi-4-mini Playground") as demo:
|
|
145 |
with gr.Column(elem_classes="header"):
|
146 |
gr.Markdown("# Phi-4-mini Playground")
|
147 |
|
148 |
-
# Main
|
149 |
-
with gr.
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
send_btn = gr.Button("📤Send", size="sm", variant="primary", scale=1)
|
167 |
-
clear = gr.Button("🗑️ Clear", size="sm", variant="secondary", scale=1)
|
168 |
-
regenerate = gr.Button("🔄 Regenerate", size="sm", variant="secondary", scale=1)
|
169 |
-
|
170 |
-
# Examples section
|
171 |
-
with gr.Accordion("Try these examples", open=True, elem_classes="examples-section"):
|
172 |
-
examples = gr.Examples(
|
173 |
-
examples=example_prompts,
|
174 |
-
inputs=msg,
|
175 |
-
# label="Financial Questions"
|
176 |
-
)
|
177 |
-
|
178 |
-
# Model parameters section
|
179 |
-
with gr.Accordion("Advanced Settings", open=False, elem_classes="parameters-section"):
|
180 |
-
with gr.Row():
|
181 |
-
with gr.Column(scale=1):
|
182 |
-
gr.Markdown("### Response Parameters")
|
183 |
|
184 |
-
|
185 |
-
with gr.Column(
|
|
|
|
|
186 |
temp_slider = gr.Slider(
|
187 |
minimum=0.0,
|
188 |
maximum=1.0,
|
@@ -191,7 +194,6 @@ with gr.Blocks(css=custom_css, title="Phi-4-mini Playground") as demo:
|
|
191 |
label="Temperature",
|
192 |
info="Higher = more creative, lower = more focused"
|
193 |
)
|
194 |
-
with gr.Column(scale=1):
|
195 |
top_p_slider = gr.Slider(
|
196 |
minimum=0.1,
|
197 |
maximum=1.0,
|
@@ -200,7 +202,6 @@ with gr.Blocks(css=custom_css, title="Phi-4-mini Playground") as demo:
|
|
200 |
label="Top P",
|
201 |
info="Controls diversity of responses"
|
202 |
)
|
203 |
-
with gr.Column(scale=1):
|
204 |
max_tokens_slider = gr.Slider(
|
205 |
minimum=100,
|
206 |
maximum=32000,
|
@@ -212,7 +213,7 @@ with gr.Blocks(css=custom_css, title="Phi-4-mini Playground") as demo:
|
|
212 |
|
213 |
# Footer
|
214 |
with gr.Column(elem_classes="footer"):
|
215 |
-
gr.Markdown("Powered by Microsoft Phi-4 mini model on Azure AI. © 2025")
|
216 |
|
217 |
# Simplified chat function that handles both sending and receiving messages
|
218 |
def chat(message, history, temperature, max_tokens, top_p):
|
@@ -295,5 +296,4 @@ with gr.Blocks(css=custom_css, title="Phi-4-mini Playground") as demo:
|
|
295 |
regenerate.click(regenerate_response, [chatbot, temp_slider, max_tokens_slider, top_p_slider], [chatbot])
|
296 |
|
297 |
# Launch the app
|
298 |
-
|
299 |
-
demo.launch(share=True) # Set share=True to generate a public URL for testing
|
|
|
34 |
"I have $20,000 in my savings account, where I receive a 4% profit per year and payments twice a year. Can you please tell me how long it will take for me to become a millionaire?",
|
35 |
"I have total $500 create a plan with travel and food",
|
36 |
"I have $1000 and 5 years. Is it better to invest in a stock paying $15 quarterly dividends or in a 5% annual savings account?"
|
|
|
37 |
]
|
38 |
|
39 |
def get_azure_response(message, chat_history, temperature, max_tokens, top_p):
|
|
|
75 |
# CSS for custom styling
|
76 |
custom_css = """
|
77 |
.container {
|
78 |
+
max-width: 1200px !important;
|
79 |
margin-left: auto !important;
|
80 |
margin-right: auto !important;
|
81 |
padding-top: 0rem !important;
|
|
|
107 |
cursor: pointer !important;
|
108 |
transition: transform 0.2s !important;
|
109 |
}
|
|
|
110 |
.emoji-button:hover {
|
111 |
transform: scale(1.2) !important;
|
112 |
}
|
|
|
113 |
.message-input {
|
114 |
margin-top: 1rem !important;
|
115 |
display: flex !important;
|
|
|
125 |
background-color: #f8f9fa !important;
|
126 |
padding: 1rem !important;
|
127 |
border-radius: 8px !important;
|
128 |
+
margin-bottom: 1rem !important;
|
129 |
}
|
130 |
.examples-section {
|
131 |
background-color: #e8f4f8 !important;
|
132 |
padding: 1rem !important;
|
133 |
border-radius: 8px !important;
|
134 |
+
margin-bottom: 1rem !important;
|
135 |
+
}
|
136 |
+
.right-panel {
|
137 |
+
padding-left: 1rem !important;
|
138 |
}
|
139 |
"""
|
140 |
|
|
|
145 |
with gr.Column(elem_classes="header"):
|
146 |
gr.Markdown("# Phi-4-mini Playground")
|
147 |
|
148 |
+
# Main content with side-by-side layout
|
149 |
+
with gr.Row():
|
150 |
+
# Left column for chat
|
151 |
+
with gr.Column(scale=7):
|
152 |
+
# Main chat interface
|
153 |
+
with gr.Column(elem_classes="chatbot-container"):
|
154 |
+
chatbot = gr.Chatbot(
|
155 |
+
height=600, # Increased height to match right panel
|
156 |
+
bubble_full_width=False,
|
157 |
+
show_label=False,
|
158 |
+
avatar_images=(None, "https://upload.wikimedia.org/wikipedia/commons/d/d3/Phi-integrated-information-symbol.png")
|
159 |
+
)
|
160 |
+
|
161 |
+
with gr.Row(elem_classes="message-input"):
|
162 |
+
msg = gr.Textbox(
|
163 |
+
label="Your message",
|
164 |
+
placeholder="Start type here ...",
|
165 |
+
lines=2,
|
166 |
+
show_label=False,
|
167 |
+
container=False,
|
168 |
+
scale=8
|
169 |
+
)
|
170 |
+
send_btn = gr.Button("📤Send", variant="primary", scale=1)
|
171 |
+
with gr.Row():
|
172 |
+
clear = gr.Button("🗑️ Clear", variant="secondary", scale=1)
|
173 |
+
regenerate = gr.Button("🔄 Regenerate", variant="secondary", scale=1)
|
174 |
|
175 |
+
# Right column for examples and settings
|
176 |
+
with gr.Column(scale=3, elem_classes="right-panel"):
|
177 |
+
# Examples section
|
178 |
+
with gr.Column(elem_classes="examples-section"):
|
179 |
+
examples = gr.Examples(
|
180 |
+
examples=example_prompts,
|
181 |
+
inputs=msg,
|
182 |
+
examples_per_page=4
|
183 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
+
# Model parameters section
|
186 |
+
with gr.Column(elem_classes="parameters-section"):
|
187 |
+
gr.Markdown("### Advanced Settings")
|
188 |
+
|
189 |
temp_slider = gr.Slider(
|
190 |
minimum=0.0,
|
191 |
maximum=1.0,
|
|
|
194 |
label="Temperature",
|
195 |
info="Higher = more creative, lower = more focused"
|
196 |
)
|
|
|
197 |
top_p_slider = gr.Slider(
|
198 |
minimum=0.1,
|
199 |
maximum=1.0,
|
|
|
202 |
label="Top P",
|
203 |
info="Controls diversity of responses"
|
204 |
)
|
|
|
205 |
max_tokens_slider = gr.Slider(
|
206 |
minimum=100,
|
207 |
maximum=32000,
|
|
|
213 |
|
214 |
# Footer
|
215 |
with gr.Column(elem_classes="footer"):
|
216 |
+
gr.Markdown("Powered by Microsoft [Phi-4 mini model](https://aka.ms/phi-4-mini/azure) on Azure AI. © 2025")
|
217 |
|
218 |
# Simplified chat function that handles both sending and receiving messages
|
219 |
def chat(message, history, temperature, max_tokens, top_p):
|
|
|
296 |
regenerate.click(regenerate_response, [chatbot, temp_slider, max_tokens_slider, top_p_slider], [chatbot])
|
297 |
|
298 |
# Launch the app
|
299 |
+
demo.launch() # Set share=True to generate a public URL for testing# Launch the app
|
|