Asterism commited on
Commit
d5236c7
1 Parent(s): fbe400f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -64
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
- def respond(message, history):
9
-
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 = {
21
- 'Content-Type': 'application/json',
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=None,
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()