Update space
Browse files
app.py
CHANGED
@@ -72,14 +72,21 @@ def extract_table(url):
|
|
72 |
except Exception as e:
|
73 |
return f"<p>Error: {str(e)}</p>"
|
74 |
|
75 |
-
def handle_prepare(index,
|
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 =
|
80 |
history.append((prompt, None))
|
81 |
return history
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
# Gradio App
|
84 |
with gr.Blocks() as demo:
|
85 |
with gr.Row():
|
@@ -109,12 +116,16 @@ with gr.Blocks() as demo:
|
|
109 |
def clear_chat():
|
110 |
return [], []
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
117 |
)
|
|
|
118 |
clear.click(clear_chat, None, [chatbot, msg])
|
119 |
|
120 |
def update_buttons():
|
@@ -129,11 +140,11 @@ with gr.Blocks() as demo:
|
|
129 |
).then(
|
130 |
respond,
|
131 |
inputs=[
|
132 |
-
lambda: f"Prepare a 10-minute reading for: {
|
133 |
-
lambda:
|
134 |
system_message
|
135 |
],
|
136 |
-
outputs=chatbot
|
137 |
)
|
138 |
|
139 |
extract_btn.click(
|
|
|
72 |
except Exception as e:
|
73 |
return f"<p>Error: {str(e)}</p>"
|
74 |
|
75 |
+
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 if history else []
|
80 |
history.append((prompt, None))
|
81 |
return history
|
82 |
|
83 |
+
def user_message(message, history, system_msg):
|
84 |
+
if message:
|
85 |
+
history = history or []
|
86 |
+
history.append((message, None))
|
87 |
+
return "", history
|
88 |
+
return "", history
|
89 |
+
|
90 |
# Gradio App
|
91 |
with gr.Blocks() as demo:
|
92 |
with gr.Row():
|
|
|
116 |
def clear_chat():
|
117 |
return [], []
|
118 |
|
119 |
+
submit.click(
|
120 |
+
user_message,
|
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, None, [chatbot, msg])
|
130 |
|
131 |
def update_buttons():
|
|
|
140 |
).then(
|
141 |
respond,
|
142 |
inputs=[
|
143 |
+
lambda: f"Prepare a 10-minute reading for: {data[i]['Topic']}",
|
144 |
+
lambda x: x if x else [],
|
145 |
system_message
|
146 |
],
|
147 |
+
outputs=[chatbot]
|
148 |
)
|
149 |
|
150 |
extract_btn.click(
|