Spaces:
Runtime error
Runtime error
Update app.py
#1
by
Asterism
- opened
app.py
CHANGED
|
@@ -1,68 +1,21 @@
|
|
| 1 |
-
import itertools
|
| 2 |
import gradio as gr
|
| 3 |
-
import requests
|
| 4 |
-
import os
|
| 5 |
-
from gradio.themes.utils import sizes
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
return "
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
'Authorization': f'Bearer {local_token}'
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
#prompt = list(itertools.chain.from_iterable(history))
|
| 26 |
-
#prompt.append(message)
|
| 27 |
-
#q = {"inputs": [prompt]}
|
| 28 |
-
q = {"inputs": [message]}
|
| 29 |
-
try:
|
| 30 |
-
response = requests.post(
|
| 31 |
-
local_endpoint, json=q, headers=headers, timeout=100)
|
| 32 |
-
response_data = response.json()
|
| 33 |
-
#print(response_data)
|
| 34 |
-
response_data=response_data["predictions"][0]
|
| 35 |
-
#print(response_data)
|
| 36 |
-
|
| 37 |
-
except Exception as error:
|
| 38 |
-
response_data = f"ERROR status_code: {type(error).__name__}"
|
| 39 |
-
# + str(response.status_code) + " response:" + response.text
|
| 40 |
-
|
| 41 |
-
# print(response.json())
|
| 42 |
-
return response_data
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
theme = gr.themes.Soft(
|
| 46 |
-
text_size=sizes.text_sm,radius_size=sizes.radius_sm, spacing_size=sizes.spacing_sm,
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
demo = gr.ChatInterface(
|
| 51 |
-
respond,
|
| 52 |
-
chatbot=gr.Chatbot(show_label=False, container=False, show_copy_button=True, bubble_full_width=True),
|
| 53 |
-
textbox=gr.Textbox(placeholder="Ask me a question",
|
| 54 |
-
container=False, scale=7),
|
| 55 |
-
title="Databricks LLM RAG demo - Chat with llama2 Databricks model serving endpoint",
|
| 56 |
-
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.",
|
| 57 |
-
examples=[["How can I start a Databricks cluster?"],
|
| 58 |
-
["What is a Databricks Cluster Policy?"],
|
| 59 |
-
["How can I track billing usage on my workspaces?"],],
|
| 60 |
-
cache_examples=False,
|
| 61 |
-
theme=theme,
|
| 62 |
retry_btn=None,
|
| 63 |
-
undo_btn=
|
| 64 |
clear_btn="Clear",
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
if __name__ == "__main__":
|
| 68 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def yes_man(message, history):
|
| 4 |
+
if message.endswith("?"):
|
| 5 |
+
return "Yes"
|
| 6 |
+
else:
|
| 7 |
+
return "Ask me anything!"
|
| 8 |
+
|
| 9 |
+
gr.ChatInterface(
|
| 10 |
+
yes_man,
|
| 11 |
+
chatbot=gr.Chatbot(height=300),
|
| 12 |
+
textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
|
| 13 |
+
title="Yes Man",
|
| 14 |
+
description="Ask Yes Man any question",
|
| 15 |
+
theme="soft",
|
| 16 |
+
examples=["Hello", "Am I cool?", "Are tomatoes vegetables?"],
|
| 17 |
+
cache_examples=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
retry_btn=None,
|
| 19 |
+
undo_btn="Delete Previous",
|
| 20 |
clear_btn="Clear",
|
| 21 |
+
).launch()
|
|
|
|
|
|
|
|
|