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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -1,9 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  def chat_response(message):
2
  if "syllabus" in message.lower():
3
- chunk_size = 500 # Ek baar me 500 characters
4
- chunks = [syllabus_text[i:i+chunk_size] for i in range(0, len(syllabus_text), chunk_size)]
5
- return "\n\n".join(chunks[:3]) # Sirf pehle 3 chunks dikhayega (1500 characters)
6
-
7
  response = chatbot(message, max_length=100, do_sample=True)
8
  return response[0]['generated_text']
 
 
 
 
 
 
9
  iface.launch()
 
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")
19
+
20
+ # πŸ“Œ Define Chat Function
21
  def chat_response(message):
22
  if "syllabus" in message.lower():
23
+ return syllabus_text
 
 
 
24
  response = chatbot(message, max_length=100, do_sample=True)
25
  return response[0]['generated_text']
26
+
27
+ # πŸ“Œ Create Gradio Interface
28
+ iface = gr.Interface(fn=chat_response, inputs="text", outputs="text", title="Bit GPT 0.2.8")
29
+
30
+ # πŸ“Œ Launch App
31
+ if __name__ == "__main__":
32
  iface.launch()