Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,8 +31,10 @@ prompt_list = [
|
|
| 31 |
]
|
| 32 |
|
| 33 |
# Generator function with GPU decorator and model loading inside
|
| 34 |
-
@spaces.GPU(duration=
|
| 35 |
def run_agent(user_content):
|
|
|
|
|
|
|
| 36 |
# Load model here to ensure GPU is available (avoids startup errors)
|
| 37 |
pipe = pipeline("text-generation", model="xingyaoww/CodeActAgent-Mistral-7b-v0.1", device_map='auto', torch_dtype=torch.bfloat16)
|
| 38 |
|
|
@@ -123,7 +125,7 @@ with gr.Blocks(title="Code Agent Simulator") as demo:
|
|
| 123 |
gr.Markdown("# Code Agent Simulator on Hugging Face Spaces\nEnter a coding task prompt, and watch the agent simulate execution in real-time.")
|
| 124 |
|
| 125 |
input_prompt = gr.Textbox(label="Enter your prompt", placeholder="e.g., Implement binary search...")
|
| 126 |
-
output_log = gr.
|
| 127 |
run_button = gr.Button("Run Simulation")
|
| 128 |
|
| 129 |
examples = gr.Examples(examples=prompt_list, inputs=[input_prompt])
|
|
@@ -131,6 +133,6 @@ with gr.Blocks(title="Code Agent Simulator") as demo:
|
|
| 131 |
# On click, run the generator and stream to output
|
| 132 |
run_button.click(fn=run_agent, inputs=input_prompt, outputs=output_log)
|
| 133 |
|
| 134 |
-
# Launch (enable queue for streaming)
|
| 135 |
if __name__ == "__main__":
|
| 136 |
-
demo.queue().launch()
|
|
|
|
| 31 |
]
|
| 32 |
|
| 33 |
# Generator function with GPU decorator and model loading inside
|
| 34 |
+
@spaces.GPU(duration=180) # Increased to 180s for multi-turn safety; no limits!
|
| 35 |
def run_agent(user_content):
|
| 36 |
+
yield "Initializing GPU and model... (this may take a moment if queued)\n\n" # Immediate feedback for visibility
|
| 37 |
+
|
| 38 |
# Load model here to ensure GPU is available (avoids startup errors)
|
| 39 |
pipe = pipeline("text-generation", model="xingyaoww/CodeActAgent-Mistral-7b-v0.1", device_map='auto', torch_dtype=torch.bfloat16)
|
| 40 |
|
|
|
|
| 125 |
gr.Markdown("# Code Agent Simulator on Hugging Face Spaces\nEnter a coding task prompt, and watch the agent simulate execution in real-time.")
|
| 126 |
|
| 127 |
input_prompt = gr.Textbox(label="Enter your prompt", placeholder="e.g., Implement binary search...")
|
| 128 |
+
output_log = gr.Textbox(value="", lines=30, autoscroll=True, show_label=True, label="Simulation Log") # Switched to Textbox for reliable real-time streaming
|
| 129 |
run_button = gr.Button("Run Simulation")
|
| 130 |
|
| 131 |
examples = gr.Examples(examples=prompt_list, inputs=[input_prompt])
|
|
|
|
| 133 |
# On click, run the generator and stream to output
|
| 134 |
run_button.click(fn=run_agent, inputs=input_prompt, outputs=output_log)
|
| 135 |
|
| 136 |
+
# Launch (enable queue for streaming, explicit SSR for ZeroGPU detection fix)
|
| 137 |
if __name__ == "__main__":
|
| 138 |
+
demo.queue().launch(ssr_mode=True) # Explicitly enable SSR to resolve ZeroGPU glitches
|