File size: 4,031 Bytes
07b1304
 
 
 
 
 
2770f19
07b1304
 
2770f19
07b1304
 
2770f19
 
07b1304
 
 
2770f19
07b1304
2770f19
 
 
07b1304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88fac70
 
 
 
07b1304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2770f19
 
 
07b1304
 
 
 
 
 
 
 
 
2770f19
 
 
 
 
 
07b1304
 
 
 
 
 
2770f19
07b1304
3263fc8
 
 
bb831a9
 
 
3263fc8
88fac70
 
 
07b1304
 
bb831a9
07b1304
 
ba8307a
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
130
131
132
133
134
135
import gradio as gr
import requests


def send_message_via_api(to_number, message):
    # response.json()API endpoint
    url = "https://whatsappv2.arnasltlt.repl.co/send"
    print(to_number)
    # Send POST request
    response = requests.post(url, data={"to_number": to_number, "message": f" {message}"})
    print(response.text)
    # Return the response or any relevant message
    to_number = to_number.replace('+', '')
    history = get_history(to_number)
    return history


def get_history(phone_number):
    # Endpoint
    to_number = phone_number.replace('+', '')
    print(to_number)
    url = f"https://whatsappv2.arnasltlt.repl.co/get_history?phone_number={to_number}"

    # 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[0]
        message = entry[1]
        html_string += f'<div class="chat-bubble {role}"><b>role: {role}</b> {message}</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='Objective',value='Find out the order status of 134JAN42')
            btn = gr.Button('Send')
            # gr.Markdown('### The conversation')
            # dt = gr.HTML(label="History")
            # demo.load(get_history, inputs=inp, outputs=dt, every=5, queue=True)
        with gr.Column():
            outcome = gr.Textbox(label='Outcome')


    # 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])

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