File size: 2,101 Bytes
b467f2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr
from rag import get_best_answer

# Custom CSS for the interface
css = """
#chatbot { 
    height: 350px; 
    overflow: auto; 
    border-radius: 10px;
    border: 1px solid #e0e0e0;
}
.textbox {
    border-radius: 20px !important;
    padding: 12px 20px !important;
}
.btn-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
"""

def create_interface():
    with gr.Blocks(css=css, theme="soft") as demo:
        gr.Markdown("""
            <h1 style='text-align: center;'>University of Education Lahore Chatbot</h1>
            <p style='text-align: center;'>Official AI Assistant for University Information</p>
        """)

        # Define the chat interface
        chatbot = gr.Chatbot(elem_id="chatbot")
        examples = [
            "What are the admission requirements?",
            "How can I contact the administration?",
            "What programs are offered?"
        ]

        with gr.Row():
            message = gr.Textbox(
                label="Type your question here",
                placeholder="Ask about admissions, programs, or university services...",
                elem_classes="textbox",
                scale=4
            )
            with gr.Column(scale=1, elem_classes="btn-column"):
                submit_button = gr.Button("↩️ Enter")
                reset_button = gr.Button("🗑️ Reset Chat")

        # Set up both Enter key and button to trigger the response
        def respond(message, chat_history):
            bot_message = get_best_answer(message)
            chat_history.append((message, bot_message))
            return "", chat_history

        message.submit(respond, [message, chatbot], [message, chatbot])
        submit_button.click(respond, [message, chatbot], [message, chatbot])

        # Reset button to clear history
        def reset_conversation():
            return []
        
        reset_button.click(reset_conversation, [], [chatbot])

        gr.Examples(examples, inputs=message)

    return demo

if __name__ == "__main__":
    demo = create_interface()
    demo.launch()