Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,31 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
|
5 |
+
# Hugging Face API endpoint URL
|
6 |
+
api_url = "https://mucdasfrkkn33hj9.us-east-1.aws.endpoints.huggingface.cloud"
|
7 |
+
|
8 |
+
# Replace <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> with your actual Hugging Face API token
|
9 |
+
headers = {
|
10 |
+
"Authorization": "Bearer <hf_token>",
|
11 |
+
"Content-Type": "application/json",
|
12 |
+
}
|
13 |
+
|
14 |
+
def chat_with_robot(inputs):
|
15 |
+
data = {
|
16 |
+
"inputs": inputs,
|
17 |
+
"parameters": {"top_k": None},
|
18 |
+
}
|
19 |
+
response = requests.post(api_url, data=json.dumps(data), headers=headers)
|
20 |
+
return response.json()["generated_text"]
|
21 |
+
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=chat_with_robot,
|
24 |
+
inputs=gr.TextInput(prompt="You:"),
|
25 |
+
outputs=gr.Textbox(prompt="Bot:"),
|
26 |
+
live=True,
|
27 |
+
title="Chat with Robot",
|
28 |
+
description="Type 'exit' to end the conversation.",
|
29 |
+
)
|
30 |
+
|
31 |
+
iface.launch()
|