Spaces:
Sleeping
Sleeping
diana3135
commited on
Commit
·
eed6b20
1
Parent(s):
299e88e
separate ai and human task description
Browse files- .gitignore +2 -1
- app.py +12 -7
- constants.py +1 -0
- instructions.py +3 -2
- utils.py +0 -1
.gitignore
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
.env
|
| 2 |
-
*.json
|
|
|
|
|
|
| 1 |
.env
|
| 2 |
+
*.json
|
| 3 |
+
ensemble-ai/
|
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from utils import *
|
|
| 3 |
from save_data import add_or_update_row_at_fixed_position, get_sheet_service
|
| 4 |
from instructions import *
|
| 5 |
from user_groups import user_data
|
| 6 |
-
from constants import SDG_DETAILS, WORD_LIMIT_MIN, GROUP_SEPERATION, LOCAL_PARAMS
|
| 7 |
from html_codes import *
|
| 8 |
|
| 9 |
class SessionManager:
|
|
@@ -142,6 +142,8 @@ def word_limit_validation(human_input):
|
|
| 142 |
words = human_input.split()
|
| 143 |
if len(words) < WORD_LIMIT_MIN:
|
| 144 |
return f"Error: Please enter at least 100 words."
|
|
|
|
|
|
|
| 145 |
return None
|
| 146 |
|
| 147 |
def on_textbox_change(session_index, session_manager, service, SHEET_ID):
|
|
@@ -176,15 +178,18 @@ if __name__ == "__main__":
|
|
| 176 |
login_status = gr.Textbox(label="Next Tasks", interactive=False)
|
| 177 |
group = gr.State()
|
| 178 |
|
| 179 |
-
with gr.Column(visible=False) as
|
| 180 |
description = gr.Textbox(label="Task Description",
|
| 181 |
-
value =
|
| 182 |
interactive=False,
|
| 183 |
lines=12)
|
| 184 |
|
| 185 |
with gr.Accordion(label = "Click to See 17 SDGs",
|
| 186 |
open=False):
|
| 187 |
gr.Markdown(SDG_DETAILS)
|
|
|
|
|
|
|
|
|
|
| 188 |
# initialization of different group contents
|
| 189 |
group_a_content = gr.Group(visible=False, elem_id="group-a")
|
| 190 |
group_b_content = gr.Group(visible=False, elem_id="group-b")
|
|
@@ -203,7 +208,7 @@ if __name__ == "__main__":
|
|
| 203 |
else:
|
| 204 |
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), invalid_group()
|
| 205 |
|
| 206 |
-
login_button.click(login, inputs=identification_code, outputs=[
|
| 207 |
|
| 208 |
|
| 209 |
|
|
@@ -220,7 +225,7 @@ if __name__ == "__main__":
|
|
| 220 |
|
| 221 |
submit_btn.click(
|
| 222 |
fn=lambda task, human_input, id: handle_create_sequential(task, human_input, session_manager, api_key, id),
|
| 223 |
-
inputs=[
|
| 224 |
outputs=[ai_output, session_index]
|
| 225 |
)
|
| 226 |
|
|
@@ -271,7 +276,7 @@ if __name__ == "__main__":
|
|
| 271 |
|
| 272 |
create_initial_btn.click(
|
| 273 |
fn=lambda task, id: handle_create_reverse_sequential(task, session_manager, api_key, id),
|
| 274 |
-
inputs=[
|
| 275 |
outputs=[initial_answer, session_index]
|
| 276 |
)
|
| 277 |
|
|
@@ -329,7 +334,7 @@ if __name__ == "__main__":
|
|
| 329 |
|
| 330 |
create_btn.click(
|
| 331 |
fn=lambda task, human_input, id: handle_create_parallel(task, human_input, session_manager, api_key, id),
|
| 332 |
-
inputs=[
|
| 333 |
outputs=[ai_initial_output, session_index]
|
| 334 |
)
|
| 335 |
|
|
|
|
| 3 |
from save_data import add_or_update_row_at_fixed_position, get_sheet_service
|
| 4 |
from instructions import *
|
| 5 |
from user_groups import user_data
|
| 6 |
+
from constants import SDG_DETAILS, WORD_LIMIT_MIN, WORD_LIMIT_MAX, GROUP_SEPERATION, LOCAL_PARAMS
|
| 7 |
from html_codes import *
|
| 8 |
|
| 9 |
class SessionManager:
|
|
|
|
| 142 |
words = human_input.split()
|
| 143 |
if len(words) < WORD_LIMIT_MIN:
|
| 144 |
return f"Error: Please enter at least 100 words."
|
| 145 |
+
elif len(words) > WORD_LIMIT_MAX:
|
| 146 |
+
return f"Error: Please enter less than 500 words."
|
| 147 |
return None
|
| 148 |
|
| 149 |
def on_textbox_change(session_index, session_manager, service, SHEET_ID):
|
|
|
|
| 178 |
login_status = gr.Textbox(label="Next Tasks", interactive=False)
|
| 179 |
group = gr.State()
|
| 180 |
|
| 181 |
+
with gr.Column(visible=False) as textbox_task:
|
| 182 |
description = gr.Textbox(label="Task Description",
|
| 183 |
+
value = human_task_description(),
|
| 184 |
interactive=False,
|
| 185 |
lines=12)
|
| 186 |
|
| 187 |
with gr.Accordion(label = "Click to See 17 SDGs",
|
| 188 |
open=False):
|
| 189 |
gr.Markdown(SDG_DETAILS)
|
| 190 |
+
|
| 191 |
+
ai_task_description = ai_task_description()
|
| 192 |
+
|
| 193 |
# initialization of different group contents
|
| 194 |
group_a_content = gr.Group(visible=False, elem_id="group-a")
|
| 195 |
group_b_content = gr.Group(visible=False, elem_id="group-b")
|
|
|
|
| 208 |
else:
|
| 209 |
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), invalid_group()
|
| 210 |
|
| 211 |
+
login_button.click(login, inputs=identification_code, outputs=[textbox_task, group_a_content, group_b_content, group_c_content, login_status])
|
| 212 |
|
| 213 |
|
| 214 |
|
|
|
|
| 225 |
|
| 226 |
submit_btn.click(
|
| 227 |
fn=lambda task, human_input, id: handle_create_sequential(task, human_input, session_manager, api_key, id),
|
| 228 |
+
inputs=[ai_task_description, human_input, identification_code],
|
| 229 |
outputs=[ai_output, session_index]
|
| 230 |
)
|
| 231 |
|
|
|
|
| 276 |
|
| 277 |
create_initial_btn.click(
|
| 278 |
fn=lambda task, id: handle_create_reverse_sequential(task, session_manager, api_key, id),
|
| 279 |
+
inputs=[ai_task_description, identification_code],
|
| 280 |
outputs=[initial_answer, session_index]
|
| 281 |
)
|
| 282 |
|
|
|
|
| 334 |
|
| 335 |
create_btn.click(
|
| 336 |
fn=lambda task, human_input, id: handle_create_parallel(task, human_input, session_manager, api_key, id),
|
| 337 |
+
inputs=[ai_task_description, human_input, identification_code],
|
| 338 |
outputs=[ai_initial_output, session_index]
|
| 339 |
)
|
| 340 |
|
constants.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
WORD_LIMIT_MIN = 100
|
|
|
|
| 2 |
GROUP_SEPERATION = 1000
|
| 3 |
LOCAL_PARAMS = False
|
| 4 |
|
|
|
|
| 1 |
WORD_LIMIT_MIN = 100
|
| 2 |
+
WORD_LIMIT_MAX = 500
|
| 3 |
GROUP_SEPERATION = 1000
|
| 4 |
LOCAL_PARAMS = False
|
| 5 |
|
instructions.py
CHANGED
|
@@ -57,8 +57,9 @@ def notes_for_participants():
|
|
| 57 |
|
| 58 |
return NOTES
|
| 59 |
|
| 60 |
-
def
|
| 61 |
# display the task description on the interface to human
|
|
|
|
| 62 |
HUMAN_TASK_DESCRIPTION = """
|
| 63 |
Given Airbnb's current business model below, please propose three ideas to make it comply with the 17 SDGs.
|
| 64 |
The final answer should be at least 100 words.
|
|
@@ -76,7 +77,7 @@ def human_task_discription():
|
|
| 76 |
"""
|
| 77 |
return HUMAN_TASK_DESCRIPTION
|
| 78 |
|
| 79 |
-
def
|
| 80 |
# task description passed to AI in the prompt
|
| 81 |
AI_TASK_DESCRIPTION = """
|
| 82 |
Given Airbnb's current business model below, please propose **three** ideas to make it comply with the 17 SDGs. Your output should be around **100** words in total.
|
|
|
|
| 57 |
|
| 58 |
return NOTES
|
| 59 |
|
| 60 |
+
def human_task_description():
|
| 61 |
# display the task description on the interface to human
|
| 62 |
+
# TODO: Decorate the text to make it more readable
|
| 63 |
HUMAN_TASK_DESCRIPTION = """
|
| 64 |
Given Airbnb's current business model below, please propose three ideas to make it comply with the 17 SDGs.
|
| 65 |
The final answer should be at least 100 words.
|
|
|
|
| 77 |
"""
|
| 78 |
return HUMAN_TASK_DESCRIPTION
|
| 79 |
|
| 80 |
+
def ai_task_description():
|
| 81 |
# task description passed to AI in the prompt
|
| 82 |
AI_TASK_DESCRIPTION = """
|
| 83 |
Given Airbnb's current business model below, please propose **three** ideas to make it comply with the 17 SDGs. Your output should be around **100** words in total.
|
utils.py
CHANGED
|
@@ -34,7 +34,6 @@ def generate_text_with_gpt(prompts, api_key = None):
|
|
| 34 |
"""Generate text using the GPT-4o model."""
|
| 35 |
if api_key:
|
| 36 |
openai.api_key = api_key
|
| 37 |
-
|
| 38 |
try:
|
| 39 |
response = openai.ChatCompletion.create(
|
| 40 |
model="gpt-4o",
|
|
|
|
| 34 |
"""Generate text using the GPT-4o model."""
|
| 35 |
if api_key:
|
| 36 |
openai.api_key = api_key
|
|
|
|
| 37 |
try:
|
| 38 |
response = openai.ChatCompletion.create(
|
| 39 |
model="gpt-4o",
|