Yingxu He
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
import os
|
2 |
import time
|
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import get_inference_endpoint
|
5 |
|
|
|
6 |
endpoint_url = os.getenv('ENDPOINT_URL')
|
7 |
personal_secret_token = os.getenv('PERSONAL_HF_TOKEN')
|
8 |
|
@@ -11,7 +13,17 @@ system_symbol = os.getenv('SYSTEM_SYMBOL')
|
|
11 |
user_symbol = os.getenv('USER_SYMBOL')
|
12 |
assistant_symbol = os.getenv('ASSISTANT_SYMBOL')
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def respond(
|
17 |
message,
|
@@ -49,11 +61,10 @@ def respond(
|
|
49 |
max_new_tokens=max_new_tokens,
|
50 |
do_sample=temperature > 0,
|
51 |
top_p=top_p,
|
52 |
-
temperature=temperature
|
53 |
-
# stream=True,
|
54 |
)
|
55 |
|
56 |
-
response =
|
57 |
"inputs": turn_breaker.join(all_messages),
|
58 |
"parameters": generation_kwargs
|
59 |
})
|
|
|
1 |
import os
|
2 |
import time
|
3 |
+
import requests
|
4 |
import gradio as gr
|
5 |
from huggingface_hub import get_inference_endpoint
|
6 |
|
7 |
+
endpoint_name = os.getenv('ENDPOINT_NAME')
|
8 |
endpoint_url = os.getenv('ENDPOINT_URL')
|
9 |
personal_secret_token = os.getenv('PERSONAL_HF_TOKEN')
|
10 |
|
|
|
13 |
user_symbol = os.getenv('USER_SYMBOL')
|
14 |
assistant_symbol = os.getenv('ASSISTANT_SYMBOL')
|
15 |
|
16 |
+
headers = {
|
17 |
+
"Accept" : "application/json",
|
18 |
+
"Authorization": f"Bearer {personal_secret_token}",
|
19 |
+
"Content-Type": "application/json"
|
20 |
+
}
|
21 |
+
|
22 |
+
def query(payload):
|
23 |
+
response = requests.post(endpoint_url, headers=headers, json=payload)
|
24 |
+
return response.json()
|
25 |
+
|
26 |
+
endpoint = get_inference_endpoint(endpoint_name, token=personal_secret_token)
|
27 |
|
28 |
def respond(
|
29 |
message,
|
|
|
61 |
max_new_tokens=max_new_tokens,
|
62 |
do_sample=temperature > 0,
|
63 |
top_p=top_p,
|
64 |
+
temperature=temperature
|
|
|
65 |
)
|
66 |
|
67 |
+
response = query({
|
68 |
"inputs": turn_breaker.join(all_messages),
|
69 |
"parameters": generation_kwargs
|
70 |
})
|