Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import requests | |
| import os | |
| # Hugging Face Inference API for Qwen3-Coder-Next (Mac model) | |
| HF_MODEL = "Qwen/Qwen3-Coder-Next" | |
| HF_TOKEN = os.getenv("HF_TOKEN") # Set this in Space Secrets | |
| HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"} if HF_TOKEN else {} | |
| def generate_response(prompt): | |
| """ | |
| Send the prompt to the Hugging Face Inference API and return the response. | |
| """ | |
| payload = {"inputs": prompt} | |
| try: | |
| response = requests.post( | |
| f"https://api-inference.huggingface.co/models/{HF_MODEL}", | |
| headers=HEADERS, | |
| json=payload, | |
| timeout=60 # prevent infinite wait | |
| ) | |
| response.raise_for_status() | |
| result = response.json() | |
| # Check if the API returned generated text | |
| if isinstance(result, list) and "generated_text" in result[0]: | |
| return result[0]["generated_text"] | |
| return str(result) | |
| except Exception as e: | |
| return f"Error: {e}" | |
| # Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Qwen3-Coder-Next — Coding Assistant") | |
| user_input = gr.Textbox(label="Prompt", placeholder="Type your code request here...") | |
| output = gr.Textbox(label="Response") | |
| user_input.submit(generate_response, inputs=user_input, outputs=output) | |
| gr.Button("Submit").click(generate_response, inputs=user_input, outputs=output) | |
| demo.launch(server_name="0.0.0.0", server_port=8080) |