Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,88 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Gradio Web Interface for Boston School Chatbot
|
3 |
-
|
4 |
-
This script creates a web interface for your chatbot using Gradio.
|
5 |
-
You only need to implement the chat function.
|
6 |
-
|
7 |
-
Key Features:
|
8 |
-
- Creates a web UI for your chatbot
|
9 |
-
- Handles conversation history
|
10 |
-
- Provides example questions
|
11 |
-
- Can be deployed to Hugging Face Spaces
|
12 |
-
|
13 |
-
Example Usage:
|
14 |
-
# Run locally:
|
15 |
-
python app.py
|
16 |
-
|
17 |
-
# Access in browser:
|
18 |
-
# http://localhost:7860
|
19 |
-
"""
|
20 |
-
|
21 |
-
import gradio as gr
|
22 |
-
from src.model import load_model
|
23 |
-
from src.chat import SchoolChatbot
|
24 |
-
|
25 |
-
def create_chatbot():
|
26 |
-
"""
|
27 |
-
Creates and configures the chatbot interface.
|
28 |
-
"""
|
29 |
-
model, tokenizer = load_model()
|
30 |
-
chatbot = SchoolChatbot(model, tokenizer)
|
31 |
-
|
32 |
-
def chat(message, history):
|
33 |
-
"""
|
34 |
-
TODO:Generate a response for the current message in a Gradio chat interface.
|
35 |
-
|
36 |
-
This function is called by Gradio's ChatInterface every time a user sends a message.
|
37 |
-
You only need to generate and return the assistant's response - Gradio handles the
|
38 |
-
chat display and history management automatically.
|
39 |
-
|
40 |
-
Args:
|
41 |
-
message (str): The current message from the user
|
42 |
-
history (list): List of previous message pairs, where each pair is
|
43 |
-
[user_message, assistant_message]
|
44 |
-
Example:
|
45 |
-
[
|
46 |
-
["What schools offer Spanish?", "The Hernandez School..."],
|
47 |
-
["Where is it located?", "The Hernandez School is in Roxbury..."]
|
48 |
-
]
|
49 |
-
|
50 |
-
Returns:
|
51 |
-
str: The assistant's response to the current message.
|
52 |
-
|
53 |
-
|
54 |
-
Note:
|
55 |
-
- Gradio automatically:
|
56 |
-
- Displays the user's message
|
57 |
-
- Displays your returned response
|
58 |
-
- Updates the chat history
|
59 |
-
- Maintains the chat interface
|
60 |
-
- You only need to:
|
61 |
-
- Generate an appropriate response to the current message
|
62 |
-
- Return that response as a string
|
63 |
-
"""
|
64 |
-
# TODO: Generate and return response
|
65 |
-
try:
|
66 |
-
# Generate response using our chatbot
|
67 |
-
response = chatbot.get_response(message)
|
68 |
-
return response
|
69 |
-
|
70 |
-
except Exception as e:
|
71 |
-
return f"I apologize, but I encountered an error. Please try again. Error: {str(e)}"
|
72 |
-
|
73 |
-
|
74 |
-
# Create Gradio interface. Customize the interface as you'd like!
|
75 |
-
demo = gr.ChatInterface(
|
76 |
-
chat,
|
77 |
-
title="Boston Public School Selection Assistant",
|
78 |
-
description="Ask me anything about Boston public schools!",
|
79 |
-
examples=[
|
80 |
-
"I live in Jamaica Plain and want to send my child to kindergarten. What schools are available?"
|
81 |
-
]
|
82 |
-
)
|
83 |
-
|
84 |
-
return demo
|
85 |
-
|
86 |
-
if __name__ == "__main__":
|
87 |
-
demo = create_chatbot()
|
88 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|