File size: 1,062 Bytes
ad7625a
 
 
 
2b03792
ad7625a
2dbe990
 
ad7625a
 
 
 
 
 
 
 
028e1e1
 
ad7625a
028e1e1
 
2b03792
2dbe990
 
 
 
38c1d86
f2030f4
2dbe990
 
f2030f4
 
2dbe990
f2030f4
2dbe990
 
 
 
2b03792
028e1e1
ad7625a
2c284fc
2dbe990
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
import gradio as gr
import traceback
from Chatbot.bot import answer_query


def chat_fn(message, history):
    history = history or []

    try:
        answer = answer_query(message)
        if not answer:
            answer = "I couldn’t process that. Please try rephrasing your question."
    except Exception:
        traceback.print_exc()
        answer = "Something went wrong while processing your request."

    history.append({"role": "user", "content": message})
    history.append({"role": "assistant", "content": answer})

    return "", history


with gr.Blocks(
    theme=gr.themes.Soft(),
    title="RailMind AI"
) as demo:

    gr.Markdown("""
    # 🚆 RailMind AI  
    Smart railway assistance for live data and verified rules
    """)

    chatbot = gr.Chatbot(height=420)

    msg = gr.Textbox(
        placeholder="Ask about train schedules, PNR status, seat availability, or railway rules…",
        show_label=False
    )

    msg.submit(chat_fn, [msg, chatbot], [msg, chatbot])


demo.launch(server_name="0.0.0.0", server_port=7860)