midrees2806 commited on
Commit
9205bd4
·
verified ·
1 Parent(s): 2978c6a

Create interface.py

Browse files
Files changed (1) hide show
  1. interface.py +70 -0
interface.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from app import get_best_answer
3
+
4
+ # Custom CSS for the interface
5
+ css = """
6
+ #chatbot {
7
+ height: 350px;
8
+ overflow: auto;
9
+ border-radius: 10px;
10
+ border: 1px solid #e0e0e0;
11
+ }
12
+ .textbox {
13
+ border-radius: 20px !important;
14
+ padding: 12px 20px !important;
15
+ }
16
+ .btn-column {
17
+ display: flex;
18
+ flex-direction: column;
19
+ gap: 10px;
20
+ }
21
+ """
22
+
23
+ def create_interface():
24
+ with gr.Blocks(css=css, theme="soft") as demo:
25
+ gr.Markdown("""
26
+ <h1 style='text-align: center;'>University of Education Lahore Chatbot</h1>
27
+ <p style='text-align: center;'>Official AI Assistant for University Information</p>
28
+ """)
29
+
30
+ # Define the chat interface
31
+ chatbot = gr.Chatbot(elem_id="chatbot")
32
+ examples = [
33
+ "What are the admission requirements?",
34
+ "How can I contact the administration?",
35
+ "What programs are offered?"
36
+ ]
37
+
38
+ with gr.Row():
39
+ message = gr.Textbox(
40
+ label="Type your question here",
41
+ placeholder="Ask about admissions, programs, or university services...",
42
+ elem_classes="textbox",
43
+ scale=4
44
+ )
45
+ with gr.Column(scale=1, elem_classes="btn-column"):
46
+ submit_button = gr.Button("↩️ Enter")
47
+ reset_button = gr.Button("🗑️ Reset Chat")
48
+
49
+ # Set up both Enter key and button to trigger the response
50
+ def respond(message, chat_history):
51
+ bot_message = get_best_answer(message)
52
+ chat_history.append((message, bot_message))
53
+ return "", chat_history
54
+
55
+ message.submit(respond, [message, chatbot], [message, chatbot])
56
+ submit_button.click(respond, [message, chatbot], [message, chatbot])
57
+
58
+ # Reset button to clear history
59
+ def reset_conversation():
60
+ return []
61
+
62
+ reset_button.click(reset_conversation, [], [chatbot])
63
+
64
+ gr.Examples(examples, inputs=message)
65
+
66
+ return demo
67
+
68
+ if __name__ == "__main__":
69
+ demo = create_interface()
70
+ demo.launch()