Update space
Browse files
app.py
CHANGED
@@ -76,17 +76,20 @@ def handle_prepare(index, history):
|
|
76 |
if 0 <= index < len(data):
|
77 |
topic = data[index]["Topic"]
|
78 |
prompt = f"Prepare a 10-minute reading on what I should know before the class for the topic: {topic}"
|
79 |
-
history = history
|
80 |
history.append((prompt, None))
|
81 |
return history
|
82 |
|
83 |
-
def
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
return "", history
|
89 |
|
|
|
|
|
|
|
90 |
# Gradio App
|
91 |
with gr.Blocks() as demo:
|
92 |
with gr.Row():
|
@@ -113,20 +116,21 @@ with gr.Blocks() as demo:
|
|
113 |
# Container for dynamic buttons
|
114 |
buttons_container = gr.Column()
|
115 |
|
116 |
-
def
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
submit.click(
|
120 |
-
|
121 |
inputs=[msg, chatbot, system_message],
|
122 |
outputs=[msg, chatbot]
|
123 |
-
).then(
|
124 |
-
respond,
|
125 |
-
inputs=[lambda x: x[-1][0] if x else "", chatbot, system_message],
|
126 |
-
outputs=[chatbot]
|
127 |
)
|
128 |
|
129 |
-
clear.click(clear_chat,
|
130 |
|
131 |
def update_buttons():
|
132 |
buttons_container.clear()
|
@@ -134,14 +138,17 @@ with gr.Blocks() as demo:
|
|
134 |
for i, row in enumerate(data):
|
135 |
btn = gr.Button(f"Prepare: {row['Topic']}")
|
136 |
btn.click(
|
137 |
-
fn=
|
138 |
-
inputs=[
|
|
|
|
|
|
|
139 |
outputs=[chatbot]
|
140 |
).then(
|
141 |
-
respond,
|
142 |
inputs=[
|
143 |
-
|
144 |
-
|
145 |
system_message
|
146 |
],
|
147 |
outputs=[chatbot]
|
|
|
76 |
if 0 <= index < len(data):
|
77 |
topic = data[index]["Topic"]
|
78 |
prompt = f"Prepare a 10-minute reading on what I should know before the class for the topic: {topic}"
|
79 |
+
history = history or []
|
80 |
history.append((prompt, None))
|
81 |
return history
|
82 |
|
83 |
+
def chat(message, history, system_msg):
|
84 |
+
history = history or []
|
85 |
+
history.append((message, None))
|
86 |
+
response = respond(message, history, system_msg)
|
87 |
+
history[-1] = (message, response)
|
88 |
return "", history
|
89 |
|
90 |
+
def clear_chat():
|
91 |
+
return [], []
|
92 |
+
|
93 |
# Gradio App
|
94 |
with gr.Blocks() as demo:
|
95 |
with gr.Row():
|
|
|
116 |
# Container for dynamic buttons
|
117 |
buttons_container = gr.Column()
|
118 |
|
119 |
+
def prepare_topic(index, history):
|
120 |
+
if 0 <= index < len(data):
|
121 |
+
topic = data[index]["Topic"]
|
122 |
+
prompt = f"Prepare a 10-minute reading for: {topic}"
|
123 |
+
history = history or []
|
124 |
+
history.append((prompt, None))
|
125 |
+
return history
|
126 |
|
127 |
submit.click(
|
128 |
+
fn=chat,
|
129 |
inputs=[msg, chatbot, system_message],
|
130 |
outputs=[msg, chatbot]
|
|
|
|
|
|
|
|
|
131 |
)
|
132 |
|
133 |
+
clear.click(fn=clear_chat, outputs=[chatbot, msg])
|
134 |
|
135 |
def update_buttons():
|
136 |
buttons_container.clear()
|
|
|
138 |
for i, row in enumerate(data):
|
139 |
btn = gr.Button(f"Prepare: {row['Topic']}")
|
140 |
btn.click(
|
141 |
+
fn=prepare_topic,
|
142 |
+
inputs=[
|
143 |
+
gr.Number(value=i, visible=False),
|
144 |
+
chatbot
|
145 |
+
],
|
146 |
outputs=[chatbot]
|
147 |
).then(
|
148 |
+
fn=respond,
|
149 |
inputs=[
|
150 |
+
gr.Textbox(value=f"Prepare a 10-minute reading for: {row['Topic']}", visible=False),
|
151 |
+
chatbot,
|
152 |
system_message
|
153 |
],
|
154 |
outputs=[chatbot]
|