Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,6 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
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}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|