File size: 1,644 Bytes
3d77d1e
 
42da822
 
 
d5efa20
 
42da822
 
 
 
 
3d77d1e
 
42da822
 
3d77d1e
 
 
42da822
3d77d1e
 
 
 
 
 
 
42da822
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

# Placeholder response function
def get_response(user_message):
    return f"رد تلقائي: {user_message}"  # Replace this with your AI model

with gr.Blocks(title="المتحدث الآلي للتشريعات المحلية لإمارة دبي") as demo:
    gr.Markdown("# Dubai Legislation Chatbot\nاسأل أي سؤال حول تشريعات دبي - نسخة تجريبية (تصميم وتنفيذ م. أسامة الخطيب)", elem_id="title")

    chatbot = gr.Chatbot(elem_id="chatbot")  
    msg = gr.Textbox(placeholder="اكتب سؤالك هنا...", rtl=True, elem_id="input-box")
    clear = gr.Button("مسح", elem_id="clear-btn")

    def user(user_message, history):
        history.append([user_message, None])
        return "", history

    def bot(history):
        user_message = history[-1][0]
        bot_message = get_response(user_message)  
        history[-1][1] = bot_message
        return history

    msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
        bot, chatbot, chatbot
    )

    clear.click(lambda: [], None, chatbot, queue=False)

# Launch with custom RTL-friendly CSS
demo.launch(css="""
#title {
    text-align: center;
    font-size: 24px;
    color: darkblue;
    direction: rtl;
}
#chatbot {
    background-color: #f9f9f9;
    border-radius: 10px;
    padding: 10px;
    direction: rtl;
    text-align: right;
    font-family: 'Tajawal', sans-serif;
}
#input-box {
    border: 2px solid blue;
    padding: 10px;
    direction: rtl;
    text-align: right;
}
#clear-btn {
    background-color: red;
    color: white;
    font-weight: bold;
}
""")