Spaces:
Build error
Build error
Commit
Β·
ac59367
1
Parent(s):
83a76fb
Fix PDF file upload and processing
Browse files
app.py
CHANGED
|
@@ -196,13 +196,18 @@ async def search_documents(query: str, top_k: int = 5):
|
|
| 196 |
raise HTTPException(status_code=500, detail=str(e))
|
| 197 |
|
| 198 |
# Gradio μΈν°νμ΄μ€ μμ±
|
| 199 |
-
def process_file(
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
def search(query):
|
| 208 |
results = vector_store.search(query)
|
|
@@ -212,7 +217,11 @@ with gr.Blocks() as demo:
|
|
| 212 |
gr.Markdown("# ParseAI PDF λΆμ μλΉμ€")
|
| 213 |
|
| 214 |
with gr.Tab("PDF μ
λ‘λ"):
|
| 215 |
-
file_input = gr.File(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
upload_button = gr.Button("μ
λ‘λ")
|
| 217 |
summary_output = gr.Textbox(label="μμ½")
|
| 218 |
|
|
|
|
| 196 |
raise HTTPException(status_code=500, detail=str(e))
|
| 197 |
|
| 198 |
# Gradio μΈν°νμ΄μ€ μμ±
|
| 199 |
+
def process_file(file_path):
|
| 200 |
+
"""Process the uploaded file and return the summary"""
|
| 201 |
+
# file_path is already a string path from Gradio's type="filepath"
|
| 202 |
+
if not file_path or not os.path.exists(file_path):
|
| 203 |
+
return "νμΌμ μ°Ύμ μ μμ΅λλ€. λ€μ μλν΄μ£ΌμΈμ."
|
| 204 |
|
| 205 |
+
try:
|
| 206 |
+
result = process_document(file_path)
|
| 207 |
+
return result.get("summary", "μμ½μ μμ±ν μ μμ΅λλ€.")
|
| 208 |
+
except Exception as e:
|
| 209 |
+
logger.error(f"Error processing file: {str(e)}")
|
| 210 |
+
return f"νμΌ μ²λ¦¬ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
| 211 |
|
| 212 |
def search(query):
|
| 213 |
results = vector_store.search(query)
|
|
|
|
| 217 |
gr.Markdown("# ParseAI PDF λΆμ μλΉμ€")
|
| 218 |
|
| 219 |
with gr.Tab("PDF μ
λ‘λ"):
|
| 220 |
+
file_input = gr.File(
|
| 221 |
+
label="PDF νμΌμ μ ννμΈμ",
|
| 222 |
+
file_types=[".pdf"],
|
| 223 |
+
type="filepath"
|
| 224 |
+
)
|
| 225 |
upload_button = gr.Button("μ
λ‘λ")
|
| 226 |
summary_output = gr.Textbox(label="μμ½")
|
| 227 |
|