bluewhale2025 commited on
Commit
ac59367
Β·
1 Parent(s): 83a76fb

Fix PDF file upload and processing

Browse files
Files changed (1) hide show
  1. app.py +16 -7
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(file):
200
- file_path = UPLOAD_DIR / file.name
201
- with open(file_path, "wb") as buffer:
202
- buffer.write(file.getbuffer())
 
203
 
204
- result = process_document(str(file_path))
205
- return result["summary"]
 
 
 
 
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(type="filepath", file_types=["pdf"])
 
 
 
 
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