Update space
Browse files
app.py
CHANGED
@@ -51,24 +51,11 @@ def extract_table(url):
|
|
51 |
})
|
52 |
|
53 |
# Generate HTML table
|
54 |
-
|
55 |
for row in data:
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
<td>{row['Topic']}</td>
|
60 |
-
</tr>
|
61 |
-
"""
|
62 |
-
html_table = f"""
|
63 |
-
<table border="1">
|
64 |
-
<tr>
|
65 |
-
<th>Date</th>
|
66 |
-
<th>Topic</th>
|
67 |
-
</tr>
|
68 |
-
{html_rows}
|
69 |
-
</table>
|
70 |
-
"""
|
71 |
-
return html_table
|
72 |
except Exception as e:
|
73 |
return f"<p>Error: {str(e)}</p>"
|
74 |
|
@@ -83,13 +70,39 @@ def handle_prepare(index, history):
|
|
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():
|
@@ -98,7 +111,7 @@ with gr.Blocks() as demo:
|
|
98 |
value="https://id2223kth.github.io/schedule/",
|
99 |
label="Table URL",
|
100 |
)
|
101 |
-
|
102 |
extract_btn = gr.Button("Extract Table")
|
103 |
|
104 |
with gr.Column(scale=2):
|
@@ -113,56 +126,27 @@ with gr.Blocks() as demo:
|
|
113 |
submit = gr.Button("Submit")
|
114 |
clear = gr.Button("Clear")
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
with buttons_container:
|
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]
|
155 |
-
)
|
156 |
-
|
157 |
-
extract_btn.click(
|
158 |
-
fn=extract_table,
|
159 |
-
inputs=[url_input],
|
160 |
-
outputs=[table_output]
|
161 |
-
).then(
|
162 |
-
fn=update_buttons,
|
163 |
-
inputs=None,
|
164 |
-
outputs=None
|
165 |
-
)
|
166 |
|
167 |
if __name__ == "__main__":
|
168 |
demo.launch()
|
|
|
51 |
})
|
52 |
|
53 |
# Generate HTML table
|
54 |
+
table_html = "<table border='1'><tr><th>Date</th><th>Topic</th></tr>"
|
55 |
for row in data:
|
56 |
+
table_html += f"<tr><td>{row['Date']}</td><td>{row['Topic']}</td></tr>"
|
57 |
+
table_html += "</table>"
|
58 |
+
return table_html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
except Exception as e:
|
60 |
return f"<p>Error: {str(e)}</p>"
|
61 |
|
|
|
70 |
def chat(message, history, system_msg):
|
71 |
history = history or []
|
72 |
history.append((message, None))
|
|
|
|
|
73 |
return "", history
|
74 |
|
75 |
def clear_chat():
|
76 |
return [], []
|
77 |
|
78 |
+
def create_table_with_buttons():
|
79 |
+
with gr.Column() as container:
|
80 |
+
# Create the table display
|
81 |
+
table_html = "<table border='1'><tr><th>Date</th><th>Topic</th></tr>"
|
82 |
+
for row in data:
|
83 |
+
table_html += f"<tr><td>{row['Date']}</td><td>{row['Topic']}</td></tr>"
|
84 |
+
table_html += "</table>"
|
85 |
+
gr.HTML(table_html)
|
86 |
+
|
87 |
+
# Create buttons below the table
|
88 |
+
with gr.Row():
|
89 |
+
for i, row in enumerate(data):
|
90 |
+
btn = gr.Button(f"Prepare: {row['Topic']}")
|
91 |
+
btn.click(
|
92 |
+
fn=handle_prepare,
|
93 |
+
inputs=[gr.Number(value=i, visible=False), chatbot],
|
94 |
+
outputs=[chatbot]
|
95 |
+
).then(
|
96 |
+
fn=respond,
|
97 |
+
inputs=[
|
98 |
+
gr.Textbox(value=f"Prepare a 10-minute reading for: {row['Topic']}", visible=False),
|
99 |
+
chatbot,
|
100 |
+
system_message
|
101 |
+
],
|
102 |
+
outputs=[chatbot]
|
103 |
+
)
|
104 |
+
return container
|
105 |
+
|
106 |
# Gradio App
|
107 |
with gr.Blocks() as demo:
|
108 |
with gr.Row():
|
|
|
111 |
value="https://id2223kth.github.io/schedule/",
|
112 |
label="Table URL",
|
113 |
)
|
114 |
+
table_container = gr.Column() # Container for table and buttons
|
115 |
extract_btn = gr.Button("Extract Table")
|
116 |
|
117 |
with gr.Column(scale=2):
|
|
|
126 |
submit = gr.Button("Submit")
|
127 |
clear = gr.Button("Clear")
|
128 |
|
129 |
+
extract_btn.click(
|
130 |
+
fn=extract_table,
|
131 |
+
inputs=[url_input],
|
132 |
+
outputs=[table_container]
|
133 |
+
).then(
|
134 |
+
fn=create_table_with_buttons,
|
135 |
+
inputs=None,
|
136 |
+
outputs=table_container
|
137 |
+
)
|
138 |
+
|
139 |
+
submit.click(
|
140 |
+
fn=chat,
|
141 |
+
inputs=[msg, chatbot, system_message],
|
142 |
+
outputs=[msg, chatbot]
|
143 |
+
).then(
|
144 |
+
fn=respond,
|
145 |
+
inputs=[msg, chatbot, system_message],
|
146 |
+
outputs=[chatbot]
|
147 |
+
)
|
148 |
+
|
149 |
+
clear.click(fn=clear_chat, outputs=[chatbot, msg])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
if __name__ == "__main__":
|
152 |
demo.launch()
|