Piux24 commited on
Commit
982dac3
·
verified ·
1 Parent(s): 3c3f0d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -30
app.py CHANGED
@@ -1,30 +1,6 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
- import PyPDF2
4
-
5
- # Load the model
6
- chatbot = pipeline("text-generation", model="facebook/blenderbot-400M-distill")
7
-
8
- # Function to read PDF
9
- def read_pdf(file_path):
10
- with open(file_path, "rb") as file:
11
- reader = PyPDF2.PdfReader(file)
12
- text = "\n".join([page.extract_text() for page in reader.pages if page.extract_text()])
13
- return text
14
-
15
- # Load syllabus
16
- syllabus_text = read_pdf("syllabus.pdf")
17
- print("Syllabus Loaded Successfully!")
18
-
19
- def chat_response(message):
20
- if "syllabus" in message.lower(): # Check if user asks about syllabus
21
- return syllabus_text[:1000] + "...\n\n(Syllabus trimmed, ask for specific topics.)"
22
- else:
23
- response = chatbot(message, max_length=100, do_sample=True)
24
- return response[0]['generated_text']
25
-
26
- # Create Gradio interface
27
- iface = gr.Interface(fn=chat_response, inputs="text", outputs="text", title="Bit GPT 0.2.8")
28
-
29
- # Launch app
30
- iface.launch()
 
1
+ try:
2
+ syllabus_text = read_pdf("syllabus.pdf")
3
+ print("Syllabus Loaded Successfully!")
4
+ except Exception as e:
5
+ syllabus_text = "Syllabus could not be loaded."
6
+ print(f"Error: {e}")