Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
def chat_response(message):
|
| 2 |
if "syllabus" in message.lower():
|
| 3 |
-
|
| 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()
|