Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
11 |
phi4_model = AutoModelForCausalLM.from_pretrained(phi4_model_path, device_map="auto", torch_dtype="auto")
|
12 |
phi4_tokenizer = AutoTokenizer.from_pretrained(phi4_model_path)
|
13 |
|
14 |
-
@spaces.GPU(duration=
|
15 |
def generate_response(user_message, max_tokens, temperature, top_k, top_p, repetition_penalty, history_state):
|
16 |
if not user_message.strip():
|
17 |
return history_state, history_state
|
@@ -133,7 +133,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
133 |
repetition_penalty_slider = gr.Slider(1.0, 2.0, value=1.0, label="Repetition Penalty")
|
134 |
|
135 |
with gr.Column(scale=4):
|
136 |
-
chatbot = gr.Chatbot(label="Chat", render_markdown=True,
|
137 |
with gr.Row():
|
138 |
user_input = gr.Textbox(label="Describe symptoms or ask a medical question", placeholder="Type your message here...", scale=3)
|
139 |
submit_button = gr.Button("Send", variant="primary", scale=1)
|
@@ -145,8 +145,17 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
145 |
example3 = gr.Button("Abdominal pain")
|
146 |
example4 = gr.Button("BMI calculation")
|
147 |
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
inputs=[user_input, max_tokens_slider, temperature_slider, top_k_slider, top_p_slider, repetition_penalty_slider, history_state],
|
151 |
outputs=[chatbot, history_state]
|
152 |
).then(
|
@@ -162,4 +171,4 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
162 |
example3.click(lambda: gr.update(value=example_messages["Abdominal pain"]), None, user_input)
|
163 |
example4.click(lambda: gr.update(value=example_messages["BMI calculation"]), None, user_input)
|
164 |
|
165 |
-
demo.launch(ssr_mode=False)
|
|
|
11 |
phi4_model = AutoModelForCausalLM.from_pretrained(phi4_model_path, device_map="auto", torch_dtype="auto")
|
12 |
phi4_tokenizer = AutoTokenizer.from_pretrained(phi4_model_path)
|
13 |
|
14 |
+
@spaces.GPU(duration=120)
|
15 |
def generate_response(user_message, max_tokens, temperature, top_k, top_p, repetition_penalty, history_state):
|
16 |
if not user_message.strip():
|
17 |
return history_state, history_state
|
|
|
133 |
repetition_penalty_slider = gr.Slider(1.0, 2.0, value=1.0, label="Repetition Penalty")
|
134 |
|
135 |
with gr.Column(scale=4):
|
136 |
+
chatbot = gr.Chatbot(label="Chat", render_markdown=True, show_copy_button=True)
|
137 |
with gr.Row():
|
138 |
user_input = gr.Textbox(label="Describe symptoms or ask a medical question", placeholder="Type your message here...", scale=3)
|
139 |
submit_button = gr.Button("Send", variant="primary", scale=1)
|
|
|
145 |
example3 = gr.Button("Abdominal pain")
|
146 |
example4 = gr.Button("BMI calculation")
|
147 |
|
148 |
+
# Replace the streaming approach with a standard click event
|
149 |
+
def process_input(message, max_tokens, temperature, top_k, top_p, repetition_penalty, history):
|
150 |
+
# Call the generator function and get the final result
|
151 |
+
generator = generate_response(message, max_tokens, temperature, top_k, top_p, repetition_penalty, history)
|
152 |
+
result = None
|
153 |
+
for res in generator:
|
154 |
+
result = res
|
155 |
+
return result
|
156 |
+
|
157 |
+
submit_button.click(
|
158 |
+
fn=process_input,
|
159 |
inputs=[user_input, max_tokens_slider, temperature_slider, top_k_slider, top_p_slider, repetition_penalty_slider, history_state],
|
160 |
outputs=[chatbot, history_state]
|
161 |
).then(
|
|
|
171 |
example3.click(lambda: gr.update(value=example_messages["Abdominal pain"]), None, user_input)
|
172 |
example4.click(lambda: gr.update(value=example_messages["BMI calculation"]), None, user_input)
|
173 |
|
174 |
+
demo.launch(ssr_mode=False)
|