Update space
Browse files
app.py
CHANGED
|
@@ -52,8 +52,18 @@ def extract_table(url):
|
|
| 52 |
'Topic': cells[1].text.strip(),
|
| 53 |
})
|
| 54 |
|
| 55 |
-
# Create HTML table with prepare buttons
|
| 56 |
-
html = '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,15 +72,7 @@ def extract_table(url):
|
|
| 62 |
<td>{row['Date']}</td>
|
| 63 |
<td>{row['Topic']}</td>
|
| 64 |
<td>
|
| 65 |
-
<button onclick=
|
| 66 |
-
(function() {{
|
| 67 |
-
const indexInput = document.getElementById("prepare-index");
|
| 68 |
-
indexInput.value = {i};
|
| 69 |
-
const event = new Event("input", {{ bubbles: true }});
|
| 70 |
-
indexInput.dispatchEvent(event);
|
| 71 |
-
document.getElementById("prepare-trigger").click();
|
| 72 |
-
}})();
|
| 73 |
-
'>
|
| 74 |
Prepare
|
| 75 |
</button>
|
| 76 |
</td>
|
|
@@ -97,15 +99,10 @@ def generate_response(history, system_message):
|
|
| 97 |
|
| 98 |
def prepare_topic_message(index):
|
| 99 |
try:
|
| 100 |
-
print(f"Received index:
|
| 101 |
|
| 102 |
-
#
|
| 103 |
-
|
| 104 |
-
idx = int(float(index))
|
| 105 |
-
except (ValueError, TypeError):
|
| 106 |
-
print(f"Invalid index value: {index}")
|
| 107 |
-
return ""
|
| 108 |
-
|
| 109 |
if 0 <= idx < len(data):
|
| 110 |
topic = data[idx]["Topic"]
|
| 111 |
date = data[idx]["Date"]
|
|
@@ -159,17 +156,17 @@ with gr.Blocks() as demo:
|
|
| 159 |
# Prepare trigger handler
|
| 160 |
prepare_trigger.click(
|
| 161 |
fn=prepare_topic_message,
|
| 162 |
-
inputs=
|
| 163 |
-
outputs=
|
| 164 |
-
|
| 165 |
-
).success(
|
| 166 |
fn=add_text,
|
| 167 |
inputs=[chatbot, msg],
|
| 168 |
-
outputs=
|
| 169 |
).then(
|
| 170 |
fn=generate_response,
|
| 171 |
inputs=[chatbot, system_message],
|
| 172 |
-
outputs=
|
| 173 |
)
|
| 174 |
|
| 175 |
# Submit button handler
|
|
|
|
| 52 |
'Topic': cells[1].text.strip(),
|
| 53 |
})
|
| 54 |
|
| 55 |
+
# Create HTML table with prepare buttons using data attributes
|
| 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 |
<td>{row['Date']}</td>
|
| 73 |
<td>{row['Topic']}</td>
|
| 74 |
<td>
|
| 75 |
+
<button onclick="prepareTopic({i})" data-index="{i}">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
Prepare
|
| 77 |
</button>
|
| 78 |
</td>
|
|
|
|
| 99 |
|
| 100 |
def prepare_topic_message(index):
|
| 101 |
try:
|
| 102 |
+
print(f"Received index: {index}") # Debug print
|
| 103 |
|
| 104 |
+
# Handle the index as a number
|
| 105 |
+
idx = int(index)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
if 0 <= idx < len(data):
|
| 107 |
topic = data[idx]["Topic"]
|
| 108 |
date = data[idx]["Date"]
|
|
|
|
| 156 |
# Prepare trigger handler
|
| 157 |
prepare_trigger.click(
|
| 158 |
fn=prepare_topic_message,
|
| 159 |
+
inputs=prepare_index,
|
| 160 |
+
outputs=msg,
|
| 161 |
+
api_name="prepare" # Add this
|
| 162 |
+
).success(
|
| 163 |
fn=add_text,
|
| 164 |
inputs=[chatbot, msg],
|
| 165 |
+
outputs=chatbot
|
| 166 |
).then(
|
| 167 |
fn=generate_response,
|
| 168 |
inputs=[chatbot, system_message],
|
| 169 |
+
outputs=chatbot
|
| 170 |
)
|
| 171 |
|
| 172 |
# Submit button handler
|