Update space
Browse files
app.py
CHANGED
@@ -93,6 +93,24 @@ def handle_prepare(index, history):
|
|
93 |
print(f"Error in handle_prepare: {e}")
|
94 |
return history or []
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
# Gradio app
|
97 |
with gr.Blocks() as demo:
|
98 |
with gr.Row():
|
@@ -124,11 +142,6 @@ with gr.Blocks() as demo:
|
|
124 |
outputs=[table_output]
|
125 |
)
|
126 |
|
127 |
-
def user_message(message, history):
|
128 |
-
history = history or []
|
129 |
-
history.append((message, None))
|
130 |
-
return "", history
|
131 |
-
|
132 |
submit.click(
|
133 |
user_message,
|
134 |
inputs=[msg, chatbot],
|
@@ -146,17 +159,10 @@ with gr.Blocks() as demo:
|
|
146 |
outputs=[chatbot]
|
147 |
).then(
|
148 |
respond,
|
149 |
-
inputs=[
|
150 |
-
lambda x: f"Prepare a 10-minute reading for topic: {data[int(x)]['Topic'] if x.isdigit() and 0 <= int(x) < len(data) else ''}",
|
151 |
-
chatbot,
|
152 |
-
system_message
|
153 |
-
],
|
154 |
outputs=[chatbot]
|
155 |
)
|
156 |
|
157 |
-
def clear_chat():
|
158 |
-
return [], []
|
159 |
-
|
160 |
clear.click(fn=clear_chat, outputs=[chatbot, msg])
|
161 |
|
162 |
if __name__ == "__main__":
|
|
|
93 |
print(f"Error in handle_prepare: {e}")
|
94 |
return history or []
|
95 |
|
96 |
+
def prepare_message(index, history, system_msg):
|
97 |
+
try:
|
98 |
+
index = int(index)
|
99 |
+
if 0 <= index < len(data):
|
100 |
+
topic = data[index]["Topic"]
|
101 |
+
return f"Prepare a 10-minute reading for topic: {topic}", history, system_msg
|
102 |
+
except Exception as e:
|
103 |
+
print(f"Error in prepare_message: {e}")
|
104 |
+
return "", history, system_msg
|
105 |
+
|
106 |
+
def user_message(message, history):
|
107 |
+
history = history or []
|
108 |
+
history.append((message, None))
|
109 |
+
return "", history
|
110 |
+
|
111 |
+
def clear_chat():
|
112 |
+
return [], []
|
113 |
+
|
114 |
# Gradio app
|
115 |
with gr.Blocks() as demo:
|
116 |
with gr.Row():
|
|
|
142 |
outputs=[table_output]
|
143 |
)
|
144 |
|
|
|
|
|
|
|
|
|
|
|
145 |
submit.click(
|
146 |
user_message,
|
147 |
inputs=[msg, chatbot],
|
|
|
159 |
outputs=[chatbot]
|
160 |
).then(
|
161 |
respond,
|
162 |
+
inputs=[prepare_input, chatbot, system_message],
|
|
|
|
|
|
|
|
|
163 |
outputs=[chatbot]
|
164 |
)
|
165 |
|
|
|
|
|
|
|
166 |
clear.click(fn=clear_chat, outputs=[chatbot, msg])
|
167 |
|
168 |
if __name__ == "__main__":
|