File size: 2,025 Bytes
8b7cf3c
e7c98db
7eb9d5e
41f9a38
622720c
 
 
7eb9d5e
8b7cf3c
622720c
8b7cf3c
 
 
 
41f9a38
8b7cf3c
 
 
7eb9d5e
8b7cf3c
 
 
 
 
 
622720c
41f9a38
622720c
 
 
 
 
 
 
41f9a38
 
 
 
 
 
622720c
2c93483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41f9a38
2c93483
 
 
622720c
2c93483
 
41f9a38
2c93483
 
622720c
2c93483
 
 
 
 
622720c
8b7cf3c
 
622720c
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
import gradio as gr
import requests

def send_message_with_secret(message, history, api_secret, bot_id):
    if not api_secret.strip():
        return "Please enter your API secret in the field above."
        
    API_URL = "https://api.kindroid.ai/v1/send-message"
    headers = {
        "Authorization": f"Bearer {api_secret}",
        "Content-Type": "application/json"
    }
    
    payload = {
        "ai_id": bot_id,
        "message": message
    }
    
    try:
        response = requests.post(API_URL, headers=headers, json=payload)
        response.raise_for_status()
        return response.content.decode()
    except requests.exceptions.RequestException as e:
        return f"An error occurred: {e}"

with gr.Blocks() as app:
    gr.Markdown("## Chat with your Kin")
    
    api_secret = gr.Textbox(
        label="API Secret",
        placeholder="Enter your API secret...",
        type="password",
        show_label=True
    )

    bot_id = gr.Textbox(
        label="Bot ID",
        placeholder="Enter your BotID...",
        show_label=True
    )
    
    chatbot = gr.Chatbot(
        value=[],
        type='messages',
        height=400
    )
    
    msg = gr.Textbox(
        label="Message",
        placeholder="Type your message here...",
        show_label=False
    )
    
    def respond(message, chat_history, api_secret):
        if not message:
            return chat_history, ""
            
        bot_response = send_message_with_secret(message, chat_history, api_secret, bot_id)
        chat_history.append({"role": "user", "content": message})
        chat_history.append({"role": "assistant", "content": bot_response})
        return chat_history, ""
    
    msg.submit(
        respond,
        inputs=[msg, chatbot, api_secret, bot_id],
        outputs=[chatbot, msg]
    )
    
    send_btn = gr.Button("Send")
    send_btn.click(
        respond,
        inputs=[msg, chatbot, api_secret],
        outputs=[chatbot, msg]
    )

if __name__ == "__main__":
    app.launch()