File size: 3,854 Bytes
07b1304
 
 
 
 
 
 
 
 
88fac70
07b1304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88fac70
 
 
 
07b1304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88fac70
 
 
 
07b1304
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import gradio as gr
import requests


def send_message_via_api(to_number, message):
    # response.json()API endpoint
    url = "https://whatsapp.arnasltlt.repl.co/send"
    print(to_number)
    # Send POST request
    response = requests.post(url, data={"to_number": to_number, "message": f"[Order {message}] Hi, What is the order status for " + message+ '?'})
    print(response.text)
    # Return the response or any relevant message
    history = get_history()
    return history


def get_history():
    # Endpoint
    url = "https://whatsapp.arnasltlt.repl.co/get_history"

    # Make a GET request
    response = requests.get(url)

    # Ensure the response was successful
    response.raise_for_status()

    html_string = """
        <html>
        <head>
            <style>
                body {
                    font-family: Arial, sans-serif;
                    background-color: #f0f0f0;
                    margin: 0;
                    padding: 20px;
                    color: black;
                }
                .chat-container {
                    display: flex;
                    flex-direction: column;
                    max-width: 400px;
                    margin: 0 auto;
                    background-color: #fff;
                    border-radius: 8px;
                    padding: 10px;
                    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
                }
                .chat-bubble {
                    padding: 10px;
                    margin: 5px 0;
                    border-radius: 15px;
                    line-height: 1.4;
                    color: black;
                }
                .chat-bubble.assistant {
                    background-color: #009688;
                    align-self: flex-start;
                }
                .chat-bubble.function {
                    background-color: gray;
                    align-self: flex-start;
                }
                .chat-bubble.user {
                    background-color: #ff5722;
                    align-self: flex-end;
                }
                #my_ai {
                    background-color: #2b524e;
                    padding:10px;
                    }
                #your_ai {
                    background-color: #c7674a;
                    padding:10px;
                }
                #your_ai_box{
                    background:#c7674a; 
                    }
                #my_ai_box{
                    background:#2b524e; 
                    border-color:black;
                    }
            </style>
        </head>
        <body>
            <div class="chat-container">
        """
    history = response.json()

    for entry in history:
        role = entry['role']
        content = entry['content']
        html_string += f'<div class="chat-bubble {role}"><b>{role.capitalize()}:</b> {content}</div>'

    html_string += """
            </div>
        </body>
        </html>
        """

    return html_string

def final_answer():
    url = "https://whatsapp.arnasltlt.repl.co/get_order_status"
    # Make a GET request
    response = requests.get(url)

    return response.text


with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            inp=gr.Textbox(label='phone',value='+37068995284')
            number= gr.Textbox(label='Order Number',value='134JAN42')
            btn = gr.Button('Send')
        with gr.Column():
            gr.Markdown('### The conversation')
            dt = gr.HTML(label="History")
            demo.load(get_history, inputs=None, outputs=dt, every=5, queue=True)
    # with gr.Row():
        # final = gr.Textbox()
        # demo.load(final_answer, inputs=None, outputs=final, every=300, queue=True)


    btn.click(fn=send_message_via_api,inputs=[inp,number],outputs=dt)

demo.queue(max_size=20)
demo.launch()