Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ system_message = "You are an assistant simulating the behavior of the participan
|
|
| 10 |
with gr.Blocks() as demo:
|
| 11 |
with gr.Row():
|
| 12 |
gr.Markdown("This application generates a focus group to answer your questions.\nFirst list your topic and questions, generate the focus group profile, get their answers and finally access the summary report")
|
| 13 |
-
with gr.Row():
|
| 14 |
with gr.Column(scale = 6):
|
| 15 |
apikey = gr.Textbox(label='Paste here your OpenAI - API key', info='No API key is stored and only you will see it.', lines = 1)
|
| 16 |
openai.api_key = os.getenv('APICode2') # openai.api_key = apikey
|
|
@@ -81,13 +81,12 @@ with gr.Blocks() as demo:
|
|
| 81 |
summary = gr.Textbox(label="Report summary", lines=50)
|
| 82 |
with gr.Row():
|
| 83 |
clear = gr.Button("Clear")
|
| 84 |
-
state = gr.State([])
|
| 85 |
|
| 86 |
def checkapiinput(apikey):
|
| 87 |
if apikey != "" and apikey is not None:
|
| 88 |
-
return gr.update(visible=True)
|
| 89 |
else:
|
| 90 |
-
return gr.update(visible=False)
|
| 91 |
|
| 92 |
def parse_participants(input_string: str) -> list:
|
| 93 |
# Replace <br> tags with newline characters
|
|
@@ -356,21 +355,13 @@ Now please provide your results.
|
|
| 356 |
result = response['choices'][0]['message']['content']
|
| 357 |
return result
|
| 358 |
|
| 359 |
-
def init_history(
|
| 360 |
-
|
| 361 |
-
messages_history += [system_message]
|
| 362 |
-
return messages_history
|
| 363 |
-
|
| 364 |
-
def printscr(chatbot):
|
| 365 |
-
print("\n\nYour chat hiatory:\n")
|
| 366 |
-
for i in range(len(chatbot)):
|
| 367 |
-
print(f"User input:{chatbot[i][0]}")
|
| 368 |
-
print(f"Bot output:{chatbot[i][1]}")
|
| 369 |
|
| 370 |
generategroup.click(generateprofiles, [title, question1, question2, question3, focusgroupdescription], [expert1, expert2, expert3, expert4, expert5, expert6, expert7, expert8, expert9, expert10])
|
| 371 |
generateresults.click(generateanswers, [title, question1, question2, question3, expert1, expert2, expert3, expert4, expert5, expert6, expert7, expert8, expert9, expert10], [response1, response2, response3, response4, response5, response6, response7, response8, response9, response10])
|
| 372 |
generatesummary.click(summarize, [title, question1, question2, question3, expert1, expert2, expert3, expert4, expert5, expert6, expert7, expert8, expert9, expert10, response1, response2, response3, response4, response5, response6, response7, response8, response9, response10], summary)
|
| 373 |
-
useapi.click(checkapiinput, apikey, fullblock)
|
| 374 |
-
|
| 375 |
|
| 376 |
demo.launch()
|
|
|
|
| 10 |
with gr.Blocks() as demo:
|
| 11 |
with gr.Row():
|
| 12 |
gr.Markdown("This application generates a focus group to answer your questions.\nFirst list your topic and questions, generate the focus group profile, get their answers and finally access the summary report")
|
| 13 |
+
with gr.Row(visible = True) as apicheck:
|
| 14 |
with gr.Column(scale = 6):
|
| 15 |
apikey = gr.Textbox(label='Paste here your OpenAI - API key', info='No API key is stored and only you will see it.', lines = 1)
|
| 16 |
openai.api_key = os.getenv('APICode2') # openai.api_key = apikey
|
|
|
|
| 81 |
summary = gr.Textbox(label="Report summary", lines=50)
|
| 82 |
with gr.Row():
|
| 83 |
clear = gr.Button("Clear")
|
|
|
|
| 84 |
|
| 85 |
def checkapiinput(apikey):
|
| 86 |
if apikey != "" and apikey is not None:
|
| 87 |
+
return gr.update(visible=True), gr.update(visible=False)
|
| 88 |
else:
|
| 89 |
+
return gr.update(visible=False), gr.update(visible=True)
|
| 90 |
|
| 91 |
def parse_participants(input_string: str) -> list:
|
| 92 |
# Replace <br> tags with newline characters
|
|
|
|
| 355 |
result = response['choices'][0]['message']['content']
|
| 356 |
return result
|
| 357 |
|
| 358 |
+
def init_history(title):
|
| 359 |
+
return "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
generategroup.click(generateprofiles, [title, question1, question2, question3, focusgroupdescription], [expert1, expert2, expert3, expert4, expert5, expert6, expert7, expert8, expert9, expert10])
|
| 362 |
generateresults.click(generateanswers, [title, question1, question2, question3, expert1, expert2, expert3, expert4, expert5, expert6, expert7, expert8, expert9, expert10], [response1, response2, response3, response4, response5, response6, response7, response8, response9, response10])
|
| 363 |
generatesummary.click(summarize, [title, question1, question2, question3, expert1, expert2, expert3, expert4, expert5, expert6, expert7, expert8, expert9, expert10, response1, response2, response3, response4, response5, response6, response7, response8, response9, response10], summary)
|
| 364 |
+
useapi.click(checkapiinput, apikey, [fullblock, apicheck])
|
| 365 |
+
clear.click(init_history, title, [title, question1, question2, question3, focusgroupdescription, expert1, expert2, expert3, expert4, expert5, expert6, expert7, expert8, expert9, expert10, response1, response2, response3, response4, response5, response6, response7, response8, response9, response10, summary])
|
| 366 |
|
| 367 |
demo.launch()
|