QL2023 commited on
Commit
6bcae89
·
verified ·
1 Parent(s): 608d3c0

Update app.py

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