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



def get_response(query, history):

    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):
    if not chat_history:
        # Display a welcome message if chat_history is empty
        welcome_message = "Welcome to the AI Trainer Chatbot! I'm here to assist you with your questions."
        chat_history = [(welcome_message, get_response(welcome_message, chat_history))]
    
    bot_message = get_response(message, chat_history)
    chat_history.append(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(css=custom_css, theme=gr.themes.Soft()) as demo:
    chatbot_title = gr.HTML('<div class="chat-title">AI Trainer Chatbot</div>')
    chatbot = gr.Chatbot()
    msg = gr.Textbox(placeholder="I am your personal AI Trainer. Ask me a question")

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


demo.launch(debug=True)