Spaces:
Sleeping
Sleeping
Update app.py
Browse files30 unmodified lines313233343536373884 unmodified lines1231241251261271281291 unmodified line13113213313413513630 unmodified lines]# Generator function with GPU decorator and model loading inside@spaces.GPU(duration=120) # Allocates GPU for up to 120s; adjust higher for complex prompts (no restrictions!)def run_agent(user_content):# Load model here to ensure GPU is available (avoids startup errors)pipe = pipeline("text-generation", model="xingyaoww/CodeActAgent-Mistral-7b-v0.1", device_map='auto', torch_dtype=torch.bfloat16)84 unmodified linesgr.Markdown("# Code Agent Simulator on Hugging Face Spaces\nEnter a coding task prompt, and watch the agent simulate execution in real-time.")input_prompt = gr.Textbox(label="Enter your prompt", placeholder="e.g., Implement binary search...")output_log = gr.Markdown(label="Simulation Log")run_button = gr.Button("Run Simulation")examples = gr.Examples(examples=prompt_list, inputs=[input_prompt])1 unmodified line# On click, run the generator and stream to outputrun_button.click(fn=run_agent, inputs=input_prompt, outputs=output_log)# Launch (enable queue for streaming)if __name__ == "__main__":demo.queue().launch()30 unmodified lines3132333435363738394084 unmodified lines1251261271281291301311 unmodified line13313413513613713830 unmodified lines]# Generator function with GPU decorator and model loading inside@spaces.GPU(duration=180) # Increased to 180s for multi-turn safety; no limits!def run_agent(user_content):yield "Initializing GPU and model... (this may take a moment if queued)\n\n" # Immediate feedback for visibility# Load model here to ensure GPU is available (avoids startup errors)pipe = pipeline("text-generation", model="xingyaoww/CodeActAgent-Mistral-7b-v0.1", device_map='auto', torch_dtype=torch.bfloat16)84 unmodified linesgr.Markdown("# Code Agent Simulator on Hugging Face Spaces\nEnter a coding task prompt, and watch the agent simulate execution in real-time.")input_prompt = gr.Textbox(label="Enter your prompt", placeholder="e.g., Implement binary search...")output_log = gr.Textbox(value="", lines=30, autoscroll=True, show_label=True, label="Simulation Log") # Switched to Textbox for reliable real-time streamingrun_button = gr.Button("Run Simulation")examples = gr.Examples(examples=prompt_list, inputs=[input_prompt])1 unmodified line# On click, run the generator and stream to outputrun_button.click(fn=run_agent, inputs=input_prompt, outputs=output_log)# Launch (enable queue for streaming, explicit SSR for ZeroGPU detection fix)if __name__ == "__main__":demo.queue().launch(ssr_mode=True) # Explicitly enable SSR to resolve ZeroGPU glitches
app.py+6-4