File size: 827 Bytes
3d2f272 9a33d64 3d2f272 9a33d64 697b8a8 9a33d64 697b8a8 9a33d64 697b8a8 9a33d64 697b8a8 9a33d64 697b8a8 9a33d64 697b8a8 9a33d64 697b8a8 9a33d64 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
import requests
import json
###Function to query Hugging Face API
def query_huggingface_api(prompt, api_url, api_key): headers = {"Authorization": f"Bearer {api_key}"} payload = {"inputs": prompt} response = requests.post(api_url, headers=headers, json=payload)
if response.status_code == 200:
return response.json()[0]['generated_text']
else:
return f"Error: API request failed with status code {response.status_code}"
Define the Gradio interface
def chat_with_model(user_input): API_URL = "https://api-inference.huggingface.co/models/YOUR_MODEL_NAME" API_KEY = "YOUR_HF_API_KEY" return query_huggingface_api(user_input, API_URL, API_KEY)
iface = gr.Interface(fn=chat_with_model, inputs="text", outputs="text", title="ChatDev AI")
Launch the Gradio app
if name == "main": iface.launch()
|