Update space
Browse files
app.py
CHANGED
@@ -52,18 +52,8 @@ def extract_table(url):
|
|
52 |
'Topic': cells[1].text.strip(),
|
53 |
})
|
54 |
|
55 |
-
# Create HTML table with prepare buttons using
|
56 |
-
html = ''
|
57 |
-
<script>
|
58 |
-
function prepareTopic(index) {
|
59 |
-
const indexInput = document.getElementById("prepare-index");
|
60 |
-
indexInput.value = index;
|
61 |
-
indexInput.dispatchEvent(new Event("input", { bubbles: true }));
|
62 |
-
document.getElementById("prepare-trigger").click();
|
63 |
-
}
|
64 |
-
</script>
|
65 |
-
'''
|
66 |
-
html += '<table class="dataframe">'
|
67 |
html += '<thead><tr><th>Date</th><th>Topic</th><th>Action</th></tr></thead>'
|
68 |
html += '<tbody>'
|
69 |
for i, row in enumerate(data):
|
@@ -72,13 +62,47 @@ def extract_table(url):
|
|
72 |
<td>{row['Date']}</td>
|
73 |
<td>{row['Topic']}</td>
|
74 |
<td>
|
75 |
-
<button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
Prepare
|
77 |
</button>
|
78 |
</td>
|
79 |
</tr>
|
80 |
'''
|
81 |
html += '</tbody></table>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
return html
|
83 |
except Exception as e:
|
84 |
return f"<p>Error: {str(e)}</p>"
|
@@ -153,16 +177,18 @@ with gr.Blocks() as demo:
|
|
153 |
outputs=[table_output]
|
154 |
)
|
155 |
|
|
|
156 |
# Prepare trigger handler
|
157 |
prepare_trigger.click(
|
158 |
fn=prepare_topic_message,
|
159 |
inputs=prepare_index,
|
160 |
outputs=msg,
|
161 |
-
|
162 |
).success(
|
163 |
fn=add_text,
|
164 |
inputs=[chatbot, msg],
|
165 |
-
outputs=chatbot
|
|
|
166 |
).then(
|
167 |
fn=generate_response,
|
168 |
inputs=[chatbot, system_message],
|
|
|
52 |
'Topic': cells[1].text.strip(),
|
53 |
})
|
54 |
|
55 |
+
# Create HTML table with prepare buttons using inline JavaScript
|
56 |
+
html = '<table class="dataframe">'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
html += '<thead><tr><th>Date</th><th>Topic</th><th>Action</th></tr></thead>'
|
58 |
html += '<tbody>'
|
59 |
for i, row in enumerate(data):
|
|
|
62 |
<td>{row['Date']}</td>
|
63 |
<td>{row['Topic']}</td>
|
64 |
<td>
|
65 |
+
<button
|
66 |
+
onclick="(() => {{
|
67 |
+
const index = document.getElementById('prepare-index');
|
68 |
+
index.value = '{i}';
|
69 |
+
index.dispatchEvent(new Event('input'));
|
70 |
+
document.getElementById('prepare-trigger').click();
|
71 |
+
}})();"
|
72 |
+
style="padding: 5px 10px; cursor: pointer; background-color: #0366d6; color: white; border: none; border-radius: 4px;"
|
73 |
+
>
|
74 |
Prepare
|
75 |
</button>
|
76 |
</td>
|
77 |
</tr>
|
78 |
'''
|
79 |
html += '</tbody></table>'
|
80 |
+
|
81 |
+
# Add some CSS to make the table look better
|
82 |
+
html = f'''
|
83 |
+
<style>
|
84 |
+
.dataframe {{
|
85 |
+
border-collapse: collapse;
|
86 |
+
width: 100%;
|
87 |
+
margin: 10px 0;
|
88 |
+
}}
|
89 |
+
.dataframe th, .dataframe td {{
|
90 |
+
border: 1px solid #ddd;
|
91 |
+
padding: 8px;
|
92 |
+
text-align: left;
|
93 |
+
}}
|
94 |
+
.dataframe th {{
|
95 |
+
background-color: #f6f8fa;
|
96 |
+
}}
|
97 |
+
.dataframe tr:nth-child(even) {{
|
98 |
+
background-color: #f9f9f9;
|
99 |
+
}}
|
100 |
+
.dataframe button:hover {{
|
101 |
+
background-color: #0056b3 !important;
|
102 |
+
}}
|
103 |
+
</style>
|
104 |
+
{html}
|
105 |
+
'''
|
106 |
return html
|
107 |
except Exception as e:
|
108 |
return f"<p>Error: {str(e)}</p>"
|
|
|
177 |
outputs=[table_output]
|
178 |
)
|
179 |
|
180 |
+
# Prepare trigger handler
|
181 |
# Prepare trigger handler
|
182 |
prepare_trigger.click(
|
183 |
fn=prepare_topic_message,
|
184 |
inputs=prepare_index,
|
185 |
outputs=msg,
|
186 |
+
queue=False # Changed from api_name to queue=False
|
187 |
).success(
|
188 |
fn=add_text,
|
189 |
inputs=[chatbot, msg],
|
190 |
+
outputs=chatbot,
|
191 |
+
queue=False
|
192 |
).then(
|
193 |
fn=generate_response,
|
194 |
inputs=[chatbot, system_message],
|