| import os | |
| import gradio as gr | |
| from openai import OpenAI | |
| # Cliente para Hugging Face Inference API | |
| client = OpenAI( | |
| base_url="https://router.huggingface.co/v1", | |
| api_key=os.environ["HF_TOKEN"], # Definido nas Secrets do Space | |
| ) | |
| def ask_model(question): | |
| completion = client.chat.completions.create( | |
| model="Qwen/Qwen3-4B-Thinking-2507:nscale", | |
| messages=[ | |
| {"role": "user", "content": question} | |
| ], | |
| ) | |
| return completion.choices[0].message.content | |
| demo = gr.Interface( | |
| fn=ask_model, | |
| inputs=gr.Textbox(label="Pergunta"), | |
| outputs=gr.Textbox(label="Resposta"), | |
| title="Minha API de IA" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |