File size: 981 Bytes
793ff90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f8844d
 
793ff90
7f8844d
91de782
793ff90
 
 
 
 
 
91de782
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import gradio as gr
from transformers import pipeline
import PyPDF2

# πŸ“Œ Load syllabus from PDF
def read_pdf(file_path):
    try:
        with open(file_path, "rb") as file:
            reader = PyPDF2.PdfReader(file)
            text = "\n".join([page.extract_text() for page in reader.pages if page.extract_text()])
        return text
    except Exception as e:
        return f"Error loading syllabus: {str(e)}"

syllabus_text = read_pdf("syllabus.pdf")

# πŸ“Œ Load AI Model
chatbot = pipeline("text-generation", model="facebook/blenderbot-400M-distill")

# πŸ“Œ Define Chat Function
def chat_response(message):
    if "syllabus" in message.lower():
        return syllabus_text
    response = chatbot(message, max_length=100, do_sample=True)
    return response[0]['generated_text']

# πŸ“Œ Create Gradio Interface
iface = gr.Interface(fn=chat_response, inputs="text", outputs="text", title="Bit GPT 0.2.8")

# πŸ“Œ Launch App
if __name__ == "__main__":
    iface.launch()