Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -122,11 +122,47 @@ def main(audio):
|
|
| 122 |
# Convert DataFrame to HTML table with editable text boxes
|
| 123 |
table_html = df.to_html(index=False, escape=False, formatters={"Answer": lambda x: f'<input type="text" value="{x}" />'})
|
| 124 |
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
# Function to handle submit button and store table data in dictionary
|
| 128 |
-
def submit_table_data(
|
| 129 |
-
tabledata =
|
| 130 |
print("Submitted Table Data: ", tabledata)
|
| 131 |
return f"Data submitted successfully! {tabledata}"
|
| 132 |
|
|
@@ -139,12 +175,11 @@ with gr.Blocks() as demo:
|
|
| 139 |
output_html = gr.HTML(label="Assessment Form")
|
| 140 |
with gr.Column():
|
| 141 |
transcribe_button = gr.Button("Transcribe and Generate Form")
|
| 142 |
-
submit_button = gr.Button("Submit")
|
|
|
|
| 143 |
|
| 144 |
-
output_textboxes = [gr.Textbox(label=question) for question in oral_health_assessment_form]
|
| 145 |
-
|
| 146 |
transcribe_button.click(fn=main, inputs=audio_input, outputs=output_html)
|
| 147 |
-
|
| 148 |
|
| 149 |
# Launch the app
|
| 150 |
demo.launch()
|
|
|
|
| 122 |
# Convert DataFrame to HTML table with editable text boxes
|
| 123 |
table_html = df.to_html(index=False, escape=False, formatters={"Answer": lambda x: f'<input type="text" value="{x}" />'})
|
| 124 |
|
| 125 |
+
# Add JavaScript to capture changes and submit
|
| 126 |
+
custom_js = """
|
| 127 |
+
<script>
|
| 128 |
+
function getTableData() {
|
| 129 |
+
var table = document.querySelector('table');
|
| 130 |
+
var data = [];
|
| 131 |
+
for (var i = 1, row; row = table.rows[i]; i++) {
|
| 132 |
+
var question = row.cells[0].innerText;
|
| 133 |
+
var answer = row.cells[1].querySelector('input').value;
|
| 134 |
+
data.push({question: question, answer: answer});
|
| 135 |
+
}
|
| 136 |
+
return data;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
function submitTableData() {
|
| 140 |
+
var data = getTableData();
|
| 141 |
+
fetch('/submit_table_data', {
|
| 142 |
+
method: 'POST',
|
| 143 |
+
headers: {
|
| 144 |
+
'Content-Type': 'application/json',
|
| 145 |
+
},
|
| 146 |
+
body: JSON.stringify(data),
|
| 147 |
+
})
|
| 148 |
+
.then(response => response.json())
|
| 149 |
+
.then(data => {
|
| 150 |
+
document.querySelector('#submit_status').innerText = 'Data submitted successfully!';
|
| 151 |
+
})
|
| 152 |
+
.catch((error) => {
|
| 153 |
+
console.error('Error:', error);
|
| 154 |
+
});
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
document.querySelector('#submit_button').addEventListener('click', submitTableData);
|
| 158 |
+
</script>
|
| 159 |
+
"""
|
| 160 |
+
|
| 161 |
+
return table_html + custom_js
|
| 162 |
|
| 163 |
# Function to handle submit button and store table data in dictionary
|
| 164 |
+
def submit_table_data(data):
|
| 165 |
+
tabledata = {item['question']: item['answer'] for item in data}
|
| 166 |
print("Submitted Table Data: ", tabledata)
|
| 167 |
return f"Data submitted successfully! {tabledata}"
|
| 168 |
|
|
|
|
| 175 |
output_html = gr.HTML(label="Assessment Form")
|
| 176 |
with gr.Column():
|
| 177 |
transcribe_button = gr.Button("Transcribe and Generate Form")
|
| 178 |
+
submit_button = gr.Button("Submit", elem_id="submit_button")
|
| 179 |
+
submit_status = gr.Textbox(label="Submit Status", elem_id="submit_status")
|
| 180 |
|
|
|
|
|
|
|
| 181 |
transcribe_button.click(fn=main, inputs=audio_input, outputs=output_html)
|
| 182 |
+
demo.add_event_listener('submit_table_data', fn=submit_table_data, inputs=None, outputs=submit_status)
|
| 183 |
|
| 184 |
# Launch the app
|
| 185 |
demo.launch()
|