File size: 971 Bytes
3fd9e1f
f1c5082
3c3f0d8
3fd9e1f
f1c5082
 
3fd9e1f
3c3f0d8
9a21e73
 
 
 
 
 
3c3f0d8
9a21e73
3c3f0d8
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
import PyPDF2

# Load the model
chatbot = pipeline("text-generation", model="facebook/blenderbot-400M-distill")

# Function to read PDF
def read_pdf(file_path):
    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

# Load syllabus
syllabus_text = read_pdf("syllabus.pdf")
print("Syllabus Loaded Successfully!")

def chat_response(message):
    if "syllabus" in message.lower():  # Check if user asks about syllabus
        return syllabus_text[:1000] + "...\n\n(Syllabus trimmed, ask for specific topics.)"
    else:
        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
iface.launch()