kwabs22 commited on
Commit
3267959
1 Parent(s): 8bf4dc2

Flexible function for different prompts to ensure group categories

Browse files
Files changed (1) hide show
  1. app.py +36 -8
app.py CHANGED
@@ -70,16 +70,30 @@ def generate_response(user_message): #generate_response_token_by_token
70
  error_message = process.stderr.read()
71
  print(f"Error: {error_message}")
72
 
73
- def custom_generate_response(cust_user_message, prompt_index):
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  """
75
- Generates a custom response based on the user message and the selected prompt,
76
- including a custom ending specific to the prompt.
77
 
78
  Parameters:
79
  - cust_user_message: The message input from the user.
80
  - prompt_index: The index of the custom prompt to use.
 
81
  """
82
- prompt, ending = CustomPrompts[prompt_index] # Unpack the prompt and its ending
83
  cust_user_message = f"{prompt}\n\n{cust_user_message}\n\n{ending}"
84
  yield from generate_response(cust_user_message)
85
 
@@ -123,18 +137,32 @@ with gr.Blocks() as iface:
123
  MainOutput = gr.TextArea(placeholder='Output will show here')
124
  CustomButtonInput = gr.TextArea(lines=1, placeholder='Prompt goes here')
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  with gr.Accordion("Random Ideas"):
127
  with gr.Group():
128
- # Dynamically create buttons and assign actions
129
  for index, (prompt, _) in enumerate(CustomPrompts):
130
  button = gr.Button(prompt)
131
- button.click(custom_generate_response, inputs=[CustomButtonInput, gr.State(index)], outputs=MainOutput)
 
132
 
133
  with gr.Accordion("General Product based", open=False):
134
  with gr.Group():
135
- # Dynamically create buttons and assign actions
136
  for index, (prompt, _) in enumerate(BusinessPrompts):
137
  button = gr.Button(prompt)
138
- button.click(custom_generate_response, inputs=[CustomButtonInput, gr.State(index)], outputs=MainOutput)
 
139
 
140
  iface.queue().launch(server_name="0.0.0.0", share=True)
 
70
  error_message = process.stderr.read()
71
  print(f"Error: {error_message}")
72
 
73
+ # def custom_generate_response(cust_user_message, prompt_index):
74
+ # """
75
+ # Generates a custom response based on the user message and the selected prompt,
76
+ # including a custom ending specific to the prompt.
77
+
78
+ # Parameters:
79
+ # - cust_user_message: The message input from the user.
80
+ # - prompt_index: The index of the custom prompt to use.
81
+ # """
82
+ # prompt, ending = CustomPrompts[prompt_index] # Unpack the prompt and its ending
83
+ # cust_user_message = f"{prompt}\n\n{cust_user_message}\n\n{ending}"
84
+ # yield from generate_response(cust_user_message)
85
+
86
+ def custom_generate_response(cust_user_message, prompt_index, prompts_list):
87
  """
88
+ Generates a custom response based on the user message, the selected prompt,
89
+ and the provided list of prompts, including a custom ending specific to the prompt.
90
 
91
  Parameters:
92
  - cust_user_message: The message input from the user.
93
  - prompt_index: The index of the custom prompt to use.
94
+ - prompts_list: The list of prompts to use for generating the response.
95
  """
96
+ prompt, ending = prompts_list[prompt_index] # Unpack the prompt and its ending from the provided list
97
  cust_user_message = f"{prompt}\n\n{cust_user_message}\n\n{ending}"
98
  yield from generate_response(cust_user_message)
99
 
 
137
  MainOutput = gr.TextArea(placeholder='Output will show here')
138
  CustomButtonInput = gr.TextArea(lines=1, placeholder='Prompt goes here')
139
 
140
+ # with gr.Accordion("Random Ideas"):
141
+ # with gr.Group():
142
+ # # Dynamically create buttons and assign actions
143
+ # for index, (prompt, _) in enumerate(CustomPrompts):
144
+ # button = gr.Button(prompt)
145
+ # button.click(custom_generate_response, inputs=[CustomButtonInput, gr.State(index)], outputs=MainOutput)
146
+
147
+ # with gr.Accordion("General Product based", open=False):
148
+ # with gr.Group():
149
+ # # Dynamically create buttons and assign actions
150
+ # for index, (prompt, _) in enumerate(BusinessPrompts):
151
+ # button = gr.Button(prompt)
152
+ # button.click(custom_generate_response, inputs=[CustomButtonInput, gr.State(index)], outputs=MainOutput)
153
+
154
  with gr.Accordion("Random Ideas"):
155
  with gr.Group():
 
156
  for index, (prompt, _) in enumerate(CustomPrompts):
157
  button = gr.Button(prompt)
158
+ # Pass CustomPrompts list as an argument
159
+ button.click(custom_generate_response, inputs=[CustomButtonInput, gr.State(index), gr.State(CustomPrompts)], outputs=MainOutput)
160
 
161
  with gr.Accordion("General Product based", open=False):
162
  with gr.Group():
 
163
  for index, (prompt, _) in enumerate(BusinessPrompts):
164
  button = gr.Button(prompt)
165
+ # Pass BusinessPrompts list as an argument
166
+ button.click(custom_generate_response, inputs=[CustomButtonInput, gr.State(index), gr.State(BusinessPrompts)], outputs=MainOutput)
167
 
168
  iface.queue().launch(server_name="0.0.0.0", share=True)