Spaces:
Sleeping
Sleeping
Mituvinci commited on
Commit ·
61edc46
1
Parent(s): 915e799
Fix Gradio 5 file handling: use filepath type instead of file object
Browse files
app.py
CHANGED
|
@@ -75,9 +75,11 @@ def run_study_session(file, mastery_threshold, progress=gr.Progress(track_tqdm=F
|
|
| 75 |
yield "Please upload a document first.", ""
|
| 76 |
return
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=ext)
|
| 80 |
-
shutil.copy2(
|
| 81 |
doc_path = tmp.name
|
| 82 |
|
| 83 |
edges.MASTERY_THRESHOLD = mastery_threshold
|
|
@@ -168,6 +170,7 @@ with gr.Blocks(title="Adaptive Study Agent") as demo:
|
|
| 168 |
file_input = gr.File(
|
| 169 |
label="Upload Document (PDF or TXT)",
|
| 170 |
file_types=[".pdf", ".txt"],
|
|
|
|
| 171 |
)
|
| 172 |
threshold_slider = gr.Slider(
|
| 173 |
minimum=0.5,
|
|
|
|
| 75 |
yield "Please upload a document first.", ""
|
| 76 |
return
|
| 77 |
|
| 78 |
+
# Gradio 5 returns a filepath string; Gradio 4 returned an object with .name
|
| 79 |
+
file_path = file if isinstance(file, str) else file.name
|
| 80 |
+
ext = os.path.splitext(file_path)[1]
|
| 81 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=ext)
|
| 82 |
+
shutil.copy2(file_path, tmp.name)
|
| 83 |
doc_path = tmp.name
|
| 84 |
|
| 85 |
edges.MASTERY_THRESHOLD = mastery_threshold
|
|
|
|
| 170 |
file_input = gr.File(
|
| 171 |
label="Upload Document (PDF or TXT)",
|
| 172 |
file_types=[".pdf", ".txt"],
|
| 173 |
+
type="filepath",
|
| 174 |
)
|
| 175 |
threshold_slider = gr.Slider(
|
| 176 |
minimum=0.5,
|