Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,42 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
'
|
| 27 |
-
'
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
gr.ChatInterface(predict).launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
root = os.environ["ROOT"]
|
| 6 |
+
#############################################################
|
| 7 |
+
|
| 8 |
+
url = root + "/api/create"
|
| 9 |
+
PARAMS = {'context1':"context1"}
|
| 10 |
+
|
| 11 |
+
response = requests.get(
|
| 12 |
+
url,
|
| 13 |
+
stream=True,
|
| 14 |
+
headers={"accept": "*/*"},
|
| 15 |
+
params = PARAMS
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
for chunk in response.iter_content(chunk_size=512):
|
| 19 |
+
thread = str(chunk, encoding="utf-8")
|
| 20 |
+
|
| 21 |
+
def predict(message, history):
|
| 22 |
+
|
| 23 |
+
url = root + "/api/chat"
|
| 24 |
+
PARAMS = {'query':message,
|
| 25 |
+
'thread':thread,
|
| 26 |
+
'context1':"context1",
|
| 27 |
+
'context2':"context2"}
|
| 28 |
+
|
| 29 |
+
response = requests.get(
|
| 30 |
+
url,
|
| 31 |
+
stream=True,
|
| 32 |
+
headers={"accept": "*/*"},
|
| 33 |
+
params = PARAMS
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
partial_message = ""
|
| 37 |
+
for chunk in response:
|
| 38 |
+
if chunk:
|
| 39 |
+
partial_message = partial_message + str(chunk, encoding="utf-8")
|
| 40 |
+
yield partial_message
|
| 41 |
+
|
|
|
|
| 42 |
gr.ChatInterface(predict).launch()
|