Piux24 commited on
Commit
3c3f0d8
·
verified ·
1 Parent(s): 9a21e73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -1,26 +1,30 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
  # Load the model
5
  chatbot = pipeline("text-generation", model="facebook/blenderbot-400M-distill")
6
 
7
- def chat_response(message):
8
- response = chatbot(message, max_length=100, do_sample=True)
9
- return response[0]['generated_text']
10
-
11
- # Create Gradio interface
12
- iface = gr.Interface(fn=chat_response, inputs="text", outputs="text", title="Bit GPT 0.2.8")
13
-
14
- # Launch app
15
- iface.launch()
16
-
17
- import PyPDF2
18
-
19
  def read_pdf(file_path):
20
  with open(file_path, "rb") as file:
21
  reader = PyPDF2.PdfReader(file)
22
  text = "\n".join([page.extract_text() for page in reader.pages if page.extract_text()])
23
  return text
24
 
 
25
  syllabus_text = read_pdf("syllabus.pdf")
26
- print("Syllabus Loaded Successfully!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()