Kadoblam commited on
Commit
9041e41
·
1 Parent(s): 695b322

Adiciona gradio_app.py para expor API no Hugging Face

Browse files
__pycache__/app.cpython-312.pyc ADDED
Binary file (1.58 kB). View file
 
gradio_app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from openai import OpenAI
4
+
5
+ # Cliente para Hugging Face Inference API
6
+ client = OpenAI(
7
+ base_url="https://router.huggingface.co/v1",
8
+ api_key=os.environ["HF_TOKEN"], # Definido nas Secrets do Space
9
+ )
10
+
11
+ def ask_model(question):
12
+ completion = client.chat.completions.create(
13
+ model="Qwen/Qwen3-4B-Thinking-2507:nscale",
14
+ messages=[
15
+ {"role": "user", "content": question}
16
+ ],
17
+ )
18
+ return completion.choices[0].message.content
19
+
20
+ demo = gr.Interface(
21
+ fn=ask_model,
22
+ inputs=gr.Textbox(label="Pergunta"),
23
+ outputs=gr.Textbox(label="Resposta"),
24
+ title="Minha API de IA"
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ demo.launch()
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
  fastapi
2
  uvicorn
3
  openai
 
 
 
 
 
1
  fastapi
2
  uvicorn
3
  openai
4
+ pydantic
5
+ gradio
6
+
7
+