Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import PyPDF2
|
|
|
4 |
|
5 |
# π Load syllabus from PDF
|
6 |
def read_pdf(file_path):
|
|
|
|
|
|
|
7 |
try:
|
8 |
with open(file_path, "rb") as file:
|
9 |
reader = PyPDF2.PdfReader(file)
|
10 |
text = "\n".join([page.extract_text() for page in reader.pages if page.extract_text()])
|
11 |
-
return text
|
12 |
except Exception as e:
|
13 |
return f"Error loading syllabus: {str(e)}"
|
14 |
|
15 |
-
syllabus_text = read_pdf("
|
16 |
|
17 |
# π Load AI Model
|
18 |
chatbot = pipeline("text-generation", model="facebook/blenderbot-400M-distill")
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import PyPDF2
|
4 |
+
import os
|
5 |
|
6 |
# π Load syllabus from PDF
|
7 |
def read_pdf(file_path):
|
8 |
+
if not os.path.exists(file_path):
|
9 |
+
return "Error: Syllabus file not found!"
|
10 |
+
|
11 |
try:
|
12 |
with open(file_path, "rb") as file:
|
13 |
reader = PyPDF2.PdfReader(file)
|
14 |
text = "\n".join([page.extract_text() for page in reader.pages if page.extract_text()])
|
15 |
+
return text if text.strip() else "Error: Could not extract text from syllabus."
|
16 |
except Exception as e:
|
17 |
return f"Error loading syllabus: {str(e)}"
|
18 |
|
19 |
+
syllabus_text = read_pdf("Syllabus.pdf") # π Ensure the filename matches exactly
|
20 |
|
21 |
# π Load AI Model
|
22 |
chatbot = pipeline("text-generation", model="facebook/blenderbot-400M-distill")
|