Spaces:
Paused
Paused
Add inference API
Browse filesSigned-off-by: Aisuko <[email protected]>
- app.py +33 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
API_TOKEN=os.getenv("HF_TOKEN")
|
6 |
+
|
7 |
+
headers = {"Authorization":f"Bearer {API_TOKEN}"}
|
8 |
+
API_URL = "https://api-inference.huggingface.co/models/microsoft/DialoGPT-large"
|
9 |
+
|
10 |
+
pass_user_inputs=[]
|
11 |
+
generated_responses=[]
|
12 |
+
|
13 |
+
def query(message, history):
|
14 |
+
global pass_user_inputs
|
15 |
+
global generated_responses
|
16 |
+
|
17 |
+
payload = {"inputs": {
|
18 |
+
"past_user_inputs": pass_user_inputs,
|
19 |
+
"generated_responses": pass_user_inputs,
|
20 |
+
"text": message,
|
21 |
+
}}
|
22 |
+
try:
|
23 |
+
response=requests.post(API_URL, headers=headers, json=payload)
|
24 |
+
if response.status_code == 200:
|
25 |
+
pass_user_inputs=response.json()['conversation']['past_user_inputs']
|
26 |
+
generated_responses=response.json()['conversation']['generated_responses']
|
27 |
+
return response.json()['generated_text']
|
28 |
+
return "Sorry, the inference API did not complete successfully."
|
29 |
+
except Exception as e:
|
30 |
+
return "Sorry, internal error. Please refresh the page and try again."
|
31 |
+
|
32 |
+
|
33 |
+
demo=gr.ChatInterface(query).launch()
|
requirements.txt
ADDED
File without changes
|