Adrian J W Thompson
commited on
Commit
·
953015d
1
Parent(s):
2279e14
added look and feel for app
Browse files
app.py
CHANGED
@@ -1,3 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
from typing import Optional, Tuple
|
3 |
|
@@ -20,12 +71,14 @@ def set_openai_api_key(api_key: str):
|
|
20 |
os.environ["OPENAI_API_KEY"] = ""
|
21 |
return chain
|
22 |
|
|
|
23 |
class ChatWrapper:
|
24 |
|
25 |
def __init__(self):
|
26 |
self.lock = Lock()
|
|
|
27 |
def __call__(
|
28 |
-
|
29 |
):
|
30 |
"""Execute the chat functionality."""
|
31 |
self.lock.acquire()
|
@@ -47,13 +100,20 @@ class ChatWrapper:
|
|
47 |
self.lock.release()
|
48 |
return history, history
|
49 |
|
|
|
50 |
chat = ChatWrapper()
|
51 |
|
52 |
-
block = gr.Blocks(css=".gradio-container {background-color:
|
53 |
|
|
|
|
|
54 |
with block:
|
55 |
with gr.Row():
|
56 |
-
gr.
|
|
|
|
|
|
|
|
|
57 |
|
58 |
openai_api_key_textbox = gr.Textbox(
|
59 |
placeholder="Paste your OpenAI API key (sk-...)",
|
@@ -81,16 +141,11 @@ with block:
|
|
81 |
inputs=message,
|
82 |
)
|
83 |
|
84 |
-
gr.HTML("Demo application of a LangChain chain.")
|
85 |
-
|
86 |
-
gr.HTML(
|
87 |
-
"<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a></center>"
|
88 |
-
)
|
89 |
-
|
90 |
state = gr.State()
|
91 |
agent_state = gr.State()
|
92 |
|
93 |
-
submit.click(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state]
|
|
|
94 |
message.submit(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
|
95 |
|
96 |
openai_api_key_textbox.change(
|
@@ -99,4 +154,13 @@ with block:
|
|
99 |
outputs=[agent_state],
|
100 |
)
|
101 |
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Hugging
|
2 |
+
Face
|
3 |
+
's logo
|
4 |
+
Hugging
|
5 |
+
Face
|
6 |
+
Search
|
7 |
+
models, datasets, users...
|
8 |
+
Models
|
9 |
+
Datasets
|
10 |
+
Spaces
|
11 |
+
Docs
|
12 |
+
Solutions
|
13 |
+
Pricing
|
14 |
+
|
15 |
+
Spaces:
|
16 |
+
|
17 |
+
thebotforge
|
18 |
+
/
|
19 |
+
chat - about - state - of - the - union
|
20 |
+
Copied
|
21 |
+
like
|
22 |
+
0
|
23 |
+
Open
|
24 |
+
logs
|
25 |
+
App
|
26 |
+
Files and versions
|
27 |
+
Community
|
28 |
+
Settings
|
29 |
+
chat - about - state - of - the - union
|
30 |
+
/
|
31 |
+
app.py
|
32 |
+
ajwthompson
|
33 |
+
's picture
|
34 |
+
ajwthompson
|
35 |
+
Update
|
36 |
+
app.py
|
37 |
+
54882
|
38 |
+
b5
|
39 |
+
about
|
40 |
+
16
|
41 |
+
hours
|
42 |
+
ago
|
43 |
+
raw
|
44 |
+
history
|
45 |
+
blame
|
46 |
+
edit
|
47 |
+
delete
|
48 |
+
No
|
49 |
+
virus
|
50 |
+
3.32
|
51 |
+
kB
|
52 |
import os
|
53 |
from typing import Optional, Tuple
|
54 |
|
|
|
71 |
os.environ["OPENAI_API_KEY"] = ""
|
72 |
return chain
|
73 |
|
74 |
+
|
75 |
class ChatWrapper:
|
76 |
|
77 |
def __init__(self):
|
78 |
self.lock = Lock()
|
79 |
+
|
80 |
def __call__(
|
81 |
+
self, api_key: str, inp: str, history: Optional[Tuple[str, str]], chain
|
82 |
):
|
83 |
"""Execute the chat functionality."""
|
84 |
self.lock.acquire()
|
|
|
100 |
self.lock.release()
|
101 |
return history, history
|
102 |
|
103 |
+
|
104 |
chat = ChatWrapper()
|
105 |
|
106 |
+
block = gr.Blocks(css=".gradio-container {background-color: #04A7E3}")
|
107 |
|
108 |
+
image_url = "https://www.thebotforge.io/wp-content/uploads/2022/01/the-bot-forge-logo-100px.png"
|
109 |
+
html = "<center><img src='%s' width='300'></center>" % image_url
|
110 |
with block:
|
111 |
with gr.Row():
|
112 |
+
gr.HTML(html)
|
113 |
+
|
114 |
+
with gr.Row():
|
115 |
+
gr.Markdown(
|
116 |
+
"<h2><center>The Bot Forge</h2></center><h3> <center>Chat about - State-of-the-Union 2023</center></h3>")
|
117 |
|
118 |
openai_api_key_textbox = gr.Textbox(
|
119 |
placeholder="Paste your OpenAI API key (sk-...)",
|
|
|
141 |
inputs=message,
|
142 |
)
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
state = gr.State()
|
145 |
agent_state = gr.State()
|
146 |
|
147 |
+
submit.click(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state],
|
148 |
+
api_name="chat")
|
149 |
message.submit(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
|
150 |
|
151 |
openai_api_key_textbox.change(
|
|
|
154 |
outputs=[agent_state],
|
155 |
)
|
156 |
|
157 |
+
|
158 |
+
def echo(name, request: gr.Request):
|
159 |
+
if request:
|
160 |
+
print("Request headers dictionary:", request.headers)
|
161 |
+
print("IP address:", request.client.host)
|
162 |
+
print("Body", request.body)
|
163 |
+
return name
|
164 |
+
|
165 |
+
|
166 |
+
block.launch(debug=True)
|