Piux24 commited on
Commit
5473ee2
Β·
verified Β·
1 Parent(s): 793ff90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
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("syllabus.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")