GageWeike's picture
Update app.py
3d4e966
raw
history blame contribute delete
843 Bytes
import gradio as gr
import requests
import json
# Hugging Face API endpoint URL
api_url = "https://mucdasfrkkn33hj9.us-east-1.aws.endpoints.huggingface.cloud"
# Replace <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> with your actual Hugging Face API token
headers = {
"Authorization": "Bearer <hf_token>",
"Content-Type": "application/json",
}
def chat_with_robot(inputs):
data = {
"inputs": inputs,
"parameters": {"top_k": None},
}
response = requests.post(api_url, data=json.dumps(data), headers=headers)
return response.json()["generated_text"]
iface = gr.Interface(
fn=chat_with_robot,
inputs=gr.inputs.TextInput(prompt="You:"),
outputs=gr.outputs.Textbox(prompt="Bot:"),
live=True,
title="Chat with Robot",
description="Type 'exit' to end the conversation.",
)
iface.launch()