Spaces:
Runtime error
Runtime error
Florent Brosse
commited on
Commit
•
1a52c2c
1
Parent(s):
12d7fe0
gradio 4.3
Browse files
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 🐠
|
|
4 |
colorFrom: green
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
4 |
colorFrom: green
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.3.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
CHANGED
@@ -2,6 +2,7 @@ import itertools
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import os
|
|
|
5 |
|
6 |
|
7 |
def respond(message, history):
|
@@ -9,10 +10,11 @@ def respond(message, history):
|
|
9 |
if len(message.strip()) == 0:
|
10 |
return "ERROR the question should not be empty"
|
11 |
|
|
|
|
|
12 |
|
13 |
-
local_token
|
14 |
-
|
15 |
-
|
16 |
|
17 |
# Add your API token to the headers
|
18 |
headers = {
|
@@ -24,30 +26,38 @@ def respond(message, history):
|
|
24 |
prompt.append(message)
|
25 |
q = {"inputs": [prompt]}
|
26 |
try:
|
27 |
-
response = requests.post(
|
|
|
28 |
response_data = response.json(
|
29 |
)["predictions"]
|
30 |
-
except:
|
31 |
-
response_data = "ERROR status_code:"
|
32 |
-
|
33 |
|
34 |
-
#print(response.json())
|
35 |
return response_data
|
36 |
|
37 |
|
|
|
|
|
|
|
|
|
|
|
38 |
demo = gr.ChatInterface(
|
39 |
respond,
|
40 |
-
chatbot=gr.Chatbot(
|
41 |
textbox=gr.Textbox(placeholder="Ask me a question",
|
42 |
container=False, scale=7),
|
43 |
title="Databricks LLM RAG demo - Chat with llama2 Databricks model serving endpoint",
|
44 |
description="This chatbot is a demo example for the dbdemos llm chatbot. <br>This content is provided as a LLM RAG educational example, without support. It is using llama2, can hallucinate and should not be used as production content.<br>Please review our dbdemos license and terms for more details.",
|
45 |
-
examples=[["How can I start a Databricks cluster?"],
|
|
|
|
|
46 |
cache_examples=False,
|
47 |
-
theme=
|
48 |
retry_btn=None,
|
49 |
undo_btn=None,
|
50 |
-
clear_btn="Clear"
|
51 |
)
|
52 |
|
53 |
if __name__ == "__main__":
|
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import os
|
5 |
+
from gradio.themes.utils import sizes
|
6 |
|
7 |
|
8 |
def respond(message, history):
|
|
|
10 |
if len(message.strip()) == 0:
|
11 |
return "ERROR the question should not be empty"
|
12 |
|
13 |
+
local_token = os.getenv('API_TOKEN')
|
14 |
+
local_endpoint = os.getenv('API_ENDPOINT')
|
15 |
|
16 |
+
if local_token is None or local_endpoint is None:
|
17 |
+
return "ERROR missing env variables"
|
|
|
18 |
|
19 |
# Add your API token to the headers
|
20 |
headers = {
|
|
|
26 |
prompt.append(message)
|
27 |
q = {"inputs": [prompt]}
|
28 |
try:
|
29 |
+
response = requests.post(
|
30 |
+
local_endpoint, json=q, headers=headers, timeout=100)
|
31 |
response_data = response.json(
|
32 |
)["predictions"]
|
33 |
+
except Exception as error:
|
34 |
+
response_data = f"ERROR status_code: {type(error).__name__}"
|
35 |
+
# + str(response.status_code) + " response:" + response.text
|
36 |
|
37 |
+
# print(response.json())
|
38 |
return response_data
|
39 |
|
40 |
|
41 |
+
theme = gr.themes.Soft(
|
42 |
+
text_size=sizes.text_sm,radius_size=sizes.radius_sm, spacing_size=sizes.spacing_sm,
|
43 |
+
)
|
44 |
+
|
45 |
+
|
46 |
demo = gr.ChatInterface(
|
47 |
respond,
|
48 |
+
chatbot=gr.Chatbot(show_label=False, container=False, show_copy_button=True, bubble_full_width=True),
|
49 |
textbox=gr.Textbox(placeholder="Ask me a question",
|
50 |
container=False, scale=7),
|
51 |
title="Databricks LLM RAG demo - Chat with llama2 Databricks model serving endpoint",
|
52 |
description="This chatbot is a demo example for the dbdemos llm chatbot. <br>This content is provided as a LLM RAG educational example, without support. It is using llama2, can hallucinate and should not be used as production content.<br>Please review our dbdemos license and terms for more details.",
|
53 |
+
examples=[["How can I start a Databricks cluster?"],
|
54 |
+
["What is a Databricks Cluster Policy?"],
|
55 |
+
["How can I track billing usage on my workspaces?"],],
|
56 |
cache_examples=False,
|
57 |
+
theme=theme,
|
58 |
retry_btn=None,
|
59 |
undo_btn=None,
|
60 |
+
clear_btn="Clear",
|
61 |
)
|
62 |
|
63 |
if __name__ == "__main__":
|