Spaces:
Sleeping
Sleeping
Adrian Cowham
commited on
Commit
β’
298c7e7
1
Parent(s):
00de715
updated prompt and readme
Browse files- README.md +4 -4
- src/app.py +9 -16
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.40.1
|
8 |
app_file: src/app.py
|
|
|
1 |
---
|
2 |
+
title: Freakonomics
|
3 |
+
emoji: π
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.40.1
|
8 |
app_file: src/app.py
|
src/app.py
CHANGED
@@ -23,8 +23,8 @@ K = 5
|
|
23 |
USE_VERBOSE = True
|
24 |
API_KEY = os.environ["OPENAI_API_KEY"]
|
25 |
system_template = """
|
26 |
-
The context below contains excerpts from '
|
27 |
-
"I'm sorry, but I can't find the answer to your question in, the book
|
28 |
|
29 |
Here is the context:
|
30 |
{context}
|
@@ -43,7 +43,7 @@ class AnswerConversationBufferMemory(ConversationBufferMemory):
|
|
43 |
return super(AnswerConversationBufferMemory, self).save_context(inputs,{'response': outputs['answer']})
|
44 |
|
45 |
def getretriever():
|
46 |
-
with open("./resources/
|
47 |
try:
|
48 |
file = read_file(uploaded_file)
|
49 |
except Exception as e:
|
@@ -95,26 +95,19 @@ def load_chain(inputs = None):
|
|
95 |
combine_docs_chain_kwargs={"prompt": qa_prompt})
|
96 |
return chain
|
97 |
|
98 |
-
CSS ="""
|
99 |
-
.contain { display: flex; flex-direction: column; }
|
100 |
-
.gradio-container { height: 100vh !important; }
|
101 |
-
#component-0 { height: 100%; }
|
102 |
-
#chatbot { flex-grow: 1; overflow: auto;}
|
103 |
-
"""
|
104 |
-
|
105 |
with gr.Blocks() as block:
|
106 |
with gr.Row():
|
107 |
with gr.Column(scale=0.75):
|
108 |
with gr.Row():
|
109 |
-
gr.Markdown("<h1>
|
110 |
with gr.Row():
|
111 |
-
gr.Markdown("by
|
112 |
chatbot = gr.Chatbot(elem_id="chatbot").style(height=600)
|
113 |
|
114 |
with gr.Row():
|
115 |
message = gr.Textbox(
|
116 |
label="",
|
117 |
-
placeholder="
|
118 |
lines=1,
|
119 |
)
|
120 |
with gr.Row():
|
@@ -129,11 +122,11 @@ with gr.Blocks() as block:
|
|
129 |
with gr.Column(scale=0.25):
|
130 |
with gr.Row():
|
131 |
gr.Markdown("<h1><center>Suggestions</center></h1>")
|
132 |
-
ex1 = gr.Button(value="
|
133 |
ex1.click(getanswer, inputs=[chain_state, ex1, state], outputs=[chatbot, state, message])
|
134 |
-
ex2 = gr.Button(value="
|
135 |
ex2.click(getanswer, inputs=[chain_state, ex2, state], outputs=[chatbot, state, message])
|
136 |
-
ex3 = gr.Button(value="
|
137 |
ex3.click(getanswer, inputs=[chain_state, ex3, state], outputs=[chatbot, state, message])
|
138 |
|
139 |
block.launch(debug=True)
|
|
|
23 |
USE_VERBOSE = True
|
24 |
API_KEY = os.environ["OPENAI_API_KEY"]
|
25 |
system_template = """
|
26 |
+
The context below contains excerpts from 'Freakonomics,' by Steven D. Levitt and Stephen J. Dubner. You must only use the information in the context below to formulate your response. If there is not enough information to formulate a response, you must respond with
|
27 |
+
"I'm sorry, but I can't find the answer to your question in, the book Freakonomics."
|
28 |
|
29 |
Here is the context:
|
30 |
{context}
|
|
|
43 |
return super(AnswerConversationBufferMemory, self).save_context(inputs,{'response': outputs['answer']})
|
44 |
|
45 |
def getretriever():
|
46 |
+
with open("./resources/Freakonomics.pdf", 'rb') as uploaded_file:
|
47 |
try:
|
48 |
file = read_file(uploaded_file)
|
49 |
except Exception as e:
|
|
|
95 |
combine_docs_chain_kwargs={"prompt": qa_prompt})
|
96 |
return chain
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
with gr.Blocks() as block:
|
99 |
with gr.Row():
|
100 |
with gr.Column(scale=0.75):
|
101 |
with gr.Row():
|
102 |
+
gr.Markdown("<h1>Freakonomics</h1>")
|
103 |
with gr.Row():
|
104 |
+
gr.Markdown("by Steven D. Levitt and Stephen J. Dubner")
|
105 |
chatbot = gr.Chatbot(elem_id="chatbot").style(height=600)
|
106 |
|
107 |
with gr.Row():
|
108 |
message = gr.Textbox(
|
109 |
label="",
|
110 |
+
placeholder="Freakonomics",
|
111 |
lines=1,
|
112 |
)
|
113 |
with gr.Row():
|
|
|
122 |
with gr.Column(scale=0.25):
|
123 |
with gr.Row():
|
124 |
gr.Markdown("<h1><center>Suggestions</center></h1>")
|
125 |
+
ex1 = gr.Button(value="How does the book challenge conventional wisdom?", variant="primary")
|
126 |
ex1.click(getanswer, inputs=[chain_state, ex1, state], outputs=[chatbot, state, message])
|
127 |
+
ex2 = gr.Button(value="What are some examples of economic principles being applied to different subjects?", variant="primary")
|
128 |
ex2.click(getanswer, inputs=[chain_state, ex2, state], outputs=[chatbot, state, message])
|
129 |
+
ex3 = gr.Button(value="How does the book explore the role of incentives?", variant="primary")
|
130 |
ex3.click(getanswer, inputs=[chain_state, ex3, state], outputs=[chatbot, state, message])
|
131 |
|
132 |
block.launch(debug=True)
|