Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -212,14 +212,31 @@ def identify_headers_with_openrouter(pdf_path, model,LLM_prompt, pages_to_check=
|
|
| 212 |
|
| 213 |
return out
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
|
|
|
|
| 217 |
iface = gr.Interface(
|
| 218 |
-
fn=
|
| 219 |
-
inputs=[
|
|
|
|
| 220 |
gr.Textbox(label="Model Type"),
|
| 221 |
-
gr.Textbox(label="LLM Prompt")
|
| 222 |
-
|
|
|
|
| 223 |
)
|
| 224 |
|
| 225 |
iface.launch()
|
|
|
|
| 212 |
|
| 213 |
return out
|
| 214 |
|
| 215 |
+
# Wrapper function to convert JSON to a dataframe-friendly format
|
| 216 |
+
def identify_headers_with_table(pdf_path, model, LLM_prompt):
|
| 217 |
+
# Call your existing function
|
| 218 |
+
result = identify_headers_with_openrouter(pdf_path, model, LLM_prompt)
|
| 219 |
+
|
| 220 |
+
# Convert list of dicts to list of lists for Gradio Dataframe
|
| 221 |
+
if not result:
|
| 222 |
+
return [] # empty table if no results
|
| 223 |
+
|
| 224 |
+
table_data = [[item['text'], item['page']+1, item['suggested_level'], item['confidence']] for item in result]
|
| 225 |
+
return table_data
|
| 226 |
+
|
| 227 |
+
# Column names for the table
|
| 228 |
+
columns = ["Text", "Page", "Suggested Level", "Confidence"]
|
| 229 |
|
| 230 |
|
| 231 |
+
# Gradio Interface
|
| 232 |
iface = gr.Interface(
|
| 233 |
+
fn=identify_headers_with_table,
|
| 234 |
+
inputs=[
|
| 235 |
+
gr.Textbox(label="Document Link"),
|
| 236 |
gr.Textbox(label="Model Type"),
|
| 237 |
+
gr.Textbox(label="LLM Prompt")
|
| 238 |
+
],
|
| 239 |
+
outputs=gr.Dataframe(headers=columns)
|
| 240 |
)
|
| 241 |
|
| 242 |
iface.launch()
|