Spaces:
Runtime error
Runtime error
Commit
·
e3519cb
0
Parent(s):
Initial commit
Browse files- .gitattributes +35 -0
- README.md +12 -0
- app.py +62 -0
- requirements.txt +2 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Chatbot
|
3 |
+
emoji: 🐠
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.49.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
|
5 |
+
|
6 |
+
def respond(message, history, endpoint, token, temp, max_token=0):
|
7 |
+
if len(message.strip()) == 0:
|
8 |
+
return "ERROR the question should not be empty"
|
9 |
+
|
10 |
+
if len(token.strip()) > 0 and len(endpoint.strip()) > 0:
|
11 |
+
local_token = token
|
12 |
+
local_endpoint = endpoint
|
13 |
+
custom_message = "[*] "
|
14 |
+
else:
|
15 |
+
local_token = os.environ['API_TOKEN']
|
16 |
+
local_endpoint = os.environ['API_ENDPOINT']
|
17 |
+
custom_message = ""
|
18 |
+
|
19 |
+
# Add your API token to the headers
|
20 |
+
headers = {
|
21 |
+
'Content-Type': 'application/json',
|
22 |
+
'Authorization': f'Bearer {local_token}'
|
23 |
+
}
|
24 |
+
q = {"inputs": {"prompt": ["Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n" +
|
25 |
+
message + "\n\n### Response:\n"], "max_tokens": [int(max_token)], "temperature": [int(temp)]}}
|
26 |
+
try:
|
27 |
+
response = requests.post(local_endpoint, json=q, headers=headers, timeout=100)
|
28 |
+
response_data = response.json(
|
29 |
+
)["predictions"][0]["candidates"][0]["text"]
|
30 |
+
except:
|
31 |
+
response_data = "ERROR status_code:" + \
|
32 |
+
str(response.status_code) + " response:" + response.text
|
33 |
+
|
34 |
+
return custom_message + response_data
|
35 |
+
|
36 |
+
|
37 |
+
demo = gr.ChatInterface(
|
38 |
+
respond,
|
39 |
+
chatbot=gr.Chatbot(height=400),
|
40 |
+
textbox=gr.Textbox(placeholder="Ask me a question",
|
41 |
+
container=False, scale=7),
|
42 |
+
title="Chat with a Databricks LLM serving endpoint",
|
43 |
+
description="This a MPT-7b model",
|
44 |
+
examples=[["Hello"], ["What is MLflow?"], ["What is Apache Spark?"]],
|
45 |
+
cache_examples=False,
|
46 |
+
theme="soft",
|
47 |
+
retry_btn=None,
|
48 |
+
undo_btn=None,
|
49 |
+
clear_btn="Clear",
|
50 |
+
additional_inputs=[
|
51 |
+
gr.Textbox(label="Custom Endpoint", type="text",
|
52 |
+
placeholder="https://XXXXXX.cloud.databricks.com/serving-endpoints/XXXXX/invocations"),
|
53 |
+
gr.Textbox(label="Custom Token", type="password",
|
54 |
+
placeholder="dapiXXXXXXXXXX"),
|
55 |
+
gr.Slider(0, 100, label="Temp", value=0),
|
56 |
+
gr.Slider(0, 100, label="Max token", value=75)
|
57 |
+
],
|
58 |
+
additional_inputs_accordion_name="Settings"
|
59 |
+
)
|
60 |
+
|
61 |
+
if __name__ == "__main__":
|
62 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|