Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import subprocess
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
import gradio as gr
|
| 5 |
-
|
| 6 |
|
| 7 |
# Set JAVA_HOME environment variable
|
| 8 |
os.environ['JAVA_HOME'] = '/usr/lib/jvm/java-11-openjdk-amd64'
|
|
@@ -78,17 +78,17 @@ def process_file(file):
|
|
| 78 |
# Define paths
|
| 79 |
pdffigures2_jar_path = "pdffigures2.jar" # Path to pdffigures2 JAR file
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
|
| 86 |
try:
|
| 87 |
# Process the PDF and get JSON data
|
| 88 |
-
print(file.name)
|
| 89 |
-
extracted_data = grade_pdf(
|
| 90 |
# Clean up the temporary input file
|
| 91 |
-
|
| 92 |
|
| 93 |
|
| 94 |
# Return JSON as a formatted string
|
|
@@ -100,9 +100,13 @@ def process_file(file):
|
|
| 100 |
def gradio_interface():
|
| 101 |
interface = gr.Interface(
|
| 102 |
fn=process_file,
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
outputs=gr.Textbox(label="Extracted JSON Data", lines=20),
|
|
|
|
| 105 |
title="PDF Grading Interface",
|
|
|
|
| 106 |
description="Upload a PDF file, and this tool will extract figures and captions as JSON."
|
| 107 |
)
|
| 108 |
return interface
|
|
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
import gradio as gr
|
| 5 |
+
import tempfile
|
| 6 |
|
| 7 |
# Set JAVA_HOME environment variable
|
| 8 |
os.environ['JAVA_HOME'] = '/usr/lib/jvm/java-11-openjdk-amd64'
|
|
|
|
| 78 |
# Define paths
|
| 79 |
pdffigures2_jar_path = "pdffigures2.jar" # Path to pdffigures2 JAR file
|
| 80 |
|
| 81 |
+
temp_input = tempfile.NamedTemporaryFile(delete=False, suffix='.pdf')
|
| 82 |
+
temp_input.write(file)
|
| 83 |
+
temp_input_path = temp_input.name
|
| 84 |
+
print("Path of the input file: ",temp_input_path)
|
| 85 |
|
| 86 |
try:
|
| 87 |
# Process the PDF and get JSON data
|
| 88 |
+
# print(file.name)
|
| 89 |
+
extracted_data = grade_pdf(temp_input_path, pdffigures2_jar_path)
|
| 90 |
# Clean up the temporary input file
|
| 91 |
+
os.unlink(temp_input_path)
|
| 92 |
|
| 93 |
|
| 94 |
# Return JSON as a formatted string
|
|
|
|
| 100 |
def gradio_interface():
|
| 101 |
interface = gr.Interface(
|
| 102 |
fn=process_file,
|
| 103 |
+
|
| 104 |
+
inputs=gr.File(label="Upload PDF File", file_types=[".pdf"], type="binary"),
|
| 105 |
+
|
| 106 |
outputs=gr.Textbox(label="Extracted JSON Data", lines=20),
|
| 107 |
+
|
| 108 |
title="PDF Grading Interface",
|
| 109 |
+
|
| 110 |
description="Upload a PDF file, and this tool will extract figures and captions as JSON."
|
| 111 |
)
|
| 112 |
return interface
|