Spaces:
Sleeping
Sleeping
Update app.py
Browse files30 unmodified lines313233343435363738394084 unmodified lines1251261271261281291301311 unmodified line13313413513413613713613830 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!)@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 lines gr.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") output_log = gr.Textbox(value="", lines=30, autoscroll=True, show_label=True, label="Simulation Log") # Switched to Textbox for reliable real-time streaming 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 output run_button.click(fn=run_agent, inputs=input_prompt, outputs=output_log)
# Launch (enable queue for streaming)# Launch (enable queue for streaming, explicit SSR for ZeroGPU detection fix)if __name__ == "__main__": demo.queue().launch() demo.queue().launch(ssr_mode=True) # Explicitly enable SSR to resolve ZeroGPU glitchesapp.py+6-4