| import gradio as gr |
| import requests |
|
|
| |
| API_URL = "https://api-inference.huggingface.co/models/Polygl0t/Tucano2-qwen-3.7B-Instruct" |
|
|
| |
| |
| |
| headers = {"Authorization": "Bearer YOUR_HF_TOKEN_HERE"} |
|
|
| def chat_with_model(user_message): |
| payload = { |
| "inputs": f"<|im_start|>user\n{user_message}<|im_end|>\n<|im_start||>assistant\n", |
| "parameters": {"max_new_tokens": 100, "return_full_text": False} |
| } |
| |
| try: |
| response = requests.post(API_URL, headers=headers, json=payload) |
| output = response.json() |
| |
| |
| if isinstance(output, list) and len(output) > 0: |
| return output[0].get('generated_text', 'Koi jawab nahi mila.') |
| elif isinstance(output, dict) and 'error' in output: |
| return f"Error: {output['error']}" |
| return str(output) |
| except Exception as e: |
| return f"Kuch gadbad hui: {str(e)}" |
|
|
| |
| demo = gr.Interface( |
| fn=chat_with_model, |
| inputs=gr.Textbox(label="Aapka Sawal", placeholder="Yahan likhein..."), |
| outputs=gr.Textbox(label="Model ka Jawab"), |
| title="Tucano2 Qwen Chat (Fast API)" |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |