Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,12 +6,13 @@ import os
|
|
6 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
7 |
|
8 |
# Initialize paths and model identifiers for easy configuration and maintenance
|
9 |
-
filename = "output_topic_details.txt" # Path to the file storing
|
10 |
-
retrieval_model_name = '
|
11 |
|
12 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
13 |
|
14 |
-
system_message = "You are an assistant specialized in distilling the user input into to
|
|
|
15 |
# Initial system message to set the behavior of the assistant
|
16 |
messages = [{"role": "system", "content": system_message}]
|
17 |
|
@@ -67,13 +68,14 @@ def generate_response(user_query, relevant_segment):
|
|
67 |
Generate a response emphasizing the bot's capability in providing scheduling information.
|
68 |
"""
|
69 |
try:
|
|
|
70 |
user_message = f"Here's a to do list based on what you said: {relevant_segment}"
|
71 |
|
72 |
# Append user's message to messages list
|
73 |
messages.append({"role": "user", "content": user_message})
|
74 |
|
75 |
response = openai.ChatCompletion.create(
|
76 |
-
model="gpt-
|
77 |
messages=messages,
|
78 |
max_tokens=200,
|
79 |
temperature=0.2,
|
@@ -100,21 +102,24 @@ def query_model(question):
|
|
100 |
"""
|
101 |
if question == "":
|
102 |
return "Hello! I am your time manager Timify! Please enter what you need to do today."
|
|
|
|
|
103 |
relevant_segment = find_relevant_segment(question, segments)
|
104 |
if not relevant_segment:
|
105 |
return "Could not find specific information. Please refine your requirements."
|
|
|
|
|
106 |
response = generate_response(question, relevant_segment)
|
107 |
return response
|
108 |
|
109 |
# Define the welcome message and specific topics the chatbot can provide information about
|
110 |
welcome_message = """
|
111 |
★Welcome to Timify!★
|
112 |
-
|
113 |
## I am your AI chatbot driven to help you with all your scheduling needs!
|
114 |
"""
|
115 |
|
116 |
topics = """
|
117 |
-
### Feel free to ask about
|
118 |
- How does Timify work?
|
119 |
- Create me a to-do list
|
120 |
- Ask me to create a daily schedule
|
@@ -123,7 +128,7 @@ topics = """
|
|
123 |
|
124 |
# Setup the Gradio Blocks interface with custom layout components
|
125 |
with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
|
126 |
-
gr.Image("Timify background.png", show_label
|
127 |
gr.Markdown(welcome_message) # Display the formatted welcome message
|
128 |
with gr.Row():
|
129 |
with gr.Column():
|
|
|
6 |
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
7 |
|
8 |
# Initialize paths and model identifiers for easy configuration and maintenance
|
9 |
+
filename = "output_topic_details.txt" # Path to the file storing to-do list examples
|
10 |
+
retrieval_model_name = 'all-MiniLM-L6-v2' # Using a pre-trained model from Hugging Face
|
11 |
|
12 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
13 |
|
14 |
+
system_message = "You are an assistant specialized in distilling the user input into a to-do list of specific items. You will then output those items in a numbered list."
|
15 |
+
|
16 |
# Initial system message to set the behavior of the assistant
|
17 |
messages = [{"role": "system", "content": system_message}]
|
18 |
|
|
|
68 |
Generate a response emphasizing the bot's capability in providing scheduling information.
|
69 |
"""
|
70 |
try:
|
71 |
+
# Use relevant segment in the message to the model
|
72 |
user_message = f"Here's a to do list based on what you said: {relevant_segment}"
|
73 |
|
74 |
# Append user's message to messages list
|
75 |
messages.append({"role": "user", "content": user_message})
|
76 |
|
77 |
response = openai.ChatCompletion.create(
|
78 |
+
model="gpt-4",
|
79 |
messages=messages,
|
80 |
max_tokens=200,
|
81 |
temperature=0.2,
|
|
|
102 |
"""
|
103 |
if question == "":
|
104 |
return "Hello! I am your time manager Timify! Please enter what you need to do today."
|
105 |
+
|
106 |
+
# Find the most relevant example segment
|
107 |
relevant_segment = find_relevant_segment(question, segments)
|
108 |
if not relevant_segment:
|
109 |
return "Could not find specific information. Please refine your requirements."
|
110 |
+
|
111 |
+
# Generate a response using the relevant example
|
112 |
response = generate_response(question, relevant_segment)
|
113 |
return response
|
114 |
|
115 |
# Define the welcome message and specific topics the chatbot can provide information about
|
116 |
welcome_message = """
|
117 |
★Welcome to Timify!★
|
|
|
118 |
## I am your AI chatbot driven to help you with all your scheduling needs!
|
119 |
"""
|
120 |
|
121 |
topics = """
|
122 |
+
### Feel free to ask about the questions below:
|
123 |
- How does Timify work?
|
124 |
- Create me a to-do list
|
125 |
- Ask me to create a daily schedule
|
|
|
128 |
|
129 |
# Setup the Gradio Blocks interface with custom layout components
|
130 |
with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
|
131 |
+
gr.Image("Timify background.png", show_label=False, show_share_button=False, show_download_button=False)
|
132 |
gr.Markdown(welcome_message) # Display the formatted welcome message
|
133 |
with gr.Row():
|
134 |
with gr.Column():
|