-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchatbot.py
107 lines (90 loc) · 3.02 KB
/
chatbot.py
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
#Import Libraries
import openai
import gradio as gr
#the API key for accessing OpenAI's services is set
openai.api_key = "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"
#Initializes a list with a system-generated message introducing the 'IntelliTax' assistant.
messages = [{"role": "system", "content": "assistant of IntelliTax"}]
#This function defines the behavior for handling user input and generating a response using the GPT model.
def CustomChatGPT(user_input):
messages.append({"role": "user", "content": user_input})
response = openai.ChatCompletion.create(
#specifying the model to use
model="gpt-3.5-turbo",
messages=messages
)
ChatGPT_reply = response["choices"][0]["message"]["content"]
messages.append({"role": "assistant", "content": ChatGPT_reply})
return ChatGPT_reply
css = """
body, html {
height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background: #E1AFD1; /* A deep blue shade */
}
body {
font-family: 'Arial', sans-serif;
color: #ffffff;
text-align: center;
}
.gradio_container {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
background-color: #AD88C6; /* A light background for the content */
border-radius: 15px;
overflow: hidden; /* Ensures the child elements do not overflow the rounded corners */
margin: 20px;
transition: transform 0.3s ease;
}
.gradio_container:hover {
transform: translateY(-5px); /* A subtle hover effect */
}
.gradio_content {
padding: 2rem; /* More padding for better spacing */
}
.input_text, .output_text, textarea, label, button {
font-size: 1rem;
border-radius: 5px;
border: 2px solid #0b3d91;
padding: 0.5rem;
margin-top: 0.5rem; /* Uniform spacing from the top */
}
.output_text, label {
color: #1b2948;
font-weight: bold;
}
button {
background-color: #0b3d91;
color: white;
border: none;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #1c1d67;
}
.title, .description {
margin-bottom: 2rem; /* More spacing above the title and description */
}
.title {
font-size: 2rem;
color: #333333;
}
.description {
font-size: 1.2rem;
color: #555555;
}
"""
# Creating a gradio Interface. This sets up the UI for the application.
demo = gr.Interface(
fn=CustomChatGPT, # The function to be called when the user submits input. 'CustomChatGPT' should be a function defined elsewhere in your code that handles the user's query.
inputs=gr.Textbox(lines=2, placeholder="Type your question here..."),
outputs="text", # Specifies that the output will be text. This is what the 'CustomChatGPT' function will return as its response.
title="IntelliTax Assistant", # The title of the web interface, which will be displayed at the top of the page.
description="This is an AI-powered tax assistant. Feel free to ask any tax-related questions!",# A brief description of the application
css=css
)
# Launches the Gradio interface
demo.launch(share=True)