File size: 2,029 Bytes
d0419af
 
 
 
 
 
 
d249abf
6250a13
d0419af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6250a13
d249abf
6250a13
d0419af
 
 
 
 
 
 
6250a13
 
d0419af
 
 
 
 
6250a13
 
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
import os
import gradio as gr
import time
from gradio_client import Client



def get_response(query, history):
    history = str(history[0][0]) + str(history[0][1])
    client = Client("https://traversaal-fitx-ai.hf.space/")
    result = client.predict(
				query,	# str in 'query' Textbox component
				history,	# str in 'history' Textbox component
				api_name="/predict"
    )
    
    return result



custom_css = """
<style>
    .gr-chatbox-container {
        border: 2px solid #007BFF;
        border-radius: 5px;
        padding: 10px;
    }
    .gr-chatbox-container .chat-history .history-item:nth-child(even) {
        background-color: #f0f0f0;
        border-radius: 5px;
        margin: 5px 0;
        padding: 10px;
    }
    .gr-chatbox-container .chat-input .text-box {
        border: 2px solid #007BFF;
        border-radius: 5px;
        padding: 10px;
    }
    .gr-chatbox-container .chat-input button {
        background-color: #007BFF;
        color: white;
        border: none;
        border-radius: 5px;
        padding: 10px 20px;
        cursor: pointer;
        transition: background-color 0.3s;
    }
    .gr-chatbox-container .chat-input button:hover {
        background-color: #0056b3;
    }
    .gr-chatbox-container .chat-title {
        font-size: 24px;
        font-weight: bold;
        margin-bottom: 10px;
    }
</style>
"""

def respond(message, chat_history):

    bot_message = get_response(message, chat_history)
    chat_history.append((message, bot_message))
    time.sleep(0.5)
    return "", chat_history

# Display the welcome message before creating the Gradio interface
welcome_message = "Welcome to the AI Trainer Chatbot! I'm here to assist you with your questions."
print(welcome_message)

with gr.Blocks(theme=gr.themes.Soft()) as demo:
    chatbot = gr.Chatbot(title="Fitx AI Chatbot")
    msg = gr.Textbox(placeholder="I am your personal AI Trainer. Ask me a question")

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


demo.launch(share=True, debug=True)