kwabs22 commited on
Commit
43b1821
1 Parent(s): f6a0b85

Dynamic buttons

Browse files
Files changed (1) hide show
  1. app.py +79 -36
app.py CHANGED
@@ -65,37 +65,88 @@ def generate_response(user_message): #generate_response_token_by_token
65
  error_message = process.stderr.read()
66
  print(f"Error: {error_message}")
67
 
68
- def custom_generate_response0(cust_user_message):
69
- cust_user_message = CustomPrompts[0] + '\n\n' + cust_user_message + '\n\nClass Diagram:'
70
- yield from generate_response(cust_user_message)
71
 
72
- def custom_generate_response1(cust_user_message):
73
- cust_user_message = CustomPrompts[1] + '\n\n' + cust_user_message + '\n\nPydot Code:'
74
- yield from generate_response(cust_user_message)
75
 
76
- def custom_generate_response2(cust_user_message):
77
- cust_user_message = CustomPrompts[2] + '\n' + cust_user_message + '\n\nScene Details'
78
- yield from generate_response(cust_user_message)
79
 
80
- def custom_generate_response3(cust_user_message):
81
- cust_user_message = CustomPrompts[3] + '\n' + cust_user_message + '\n\nTeardown Details:'
82
- yield from generate_response(cust_user_message)
83
 
84
- def custom_generate_response4(cust_user_message):
85
- cust_user_message = CustomPrompts[4] + '\n' + cust_user_message + '\n\nManufacturing Details:'
86
- yield from generate_response(cust_user_message)
 
 
 
 
87
 
88
- def custom_generate_response5(cust_user_message):
89
- cust_user_message = CustomPrompts[5] + '\n' + cust_user_message + '\n\nConsiderations:'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  yield from generate_response(cust_user_message)
91
 
92
  CustomPrompts = [
93
- "Write a Class Diagram based on the following text:",
94
- "Write a Pydot code based on the following text:",
95
- "Describe what a standard happy scene in any movie would be planned in great detail, based on the following text:",
96
- "Explain a teardown of the product mentioned in the following text:",
97
- "Explain the manufacturing of the product mentioned in the following text:",
98
- "Explain the marketing considerations of the product mentioned in the following text:",
 
99
  ]
100
 
101
  with gr.Blocks() as iface:
@@ -107,23 +158,15 @@ with gr.Blocks() as iface:
107
  description="No Prompt template used yet (Essentially autocomplete). No Message History for now - Enter your message and get a response.",
108
  flagging_dir="/usr/src/app/flagged",
109
  )
110
- #gr.Interface(fn=generate_response_token_by_token, inputs=gr.Textbox(lines=2, placeholder='Type prompt here...'), outputs="text", description="More Responsive streaming test")
111
  with gr.Group():
112
  gr.HTML("Test for wrapping generator (Instead of buttons tabs and dropdowns?)")
113
  MainOutput = gr.TextArea(placeholder='Output will show here')
114
  CustomButtonInput = gr.TextArea(lines=1, placeholder='Prompt goes here')
115
- CustomButtonTeardown = gr.Button(CustomPrompts[3])
116
- CustomButtonManufacture = gr.Button(CustomPrompts[4])
117
- CustomButtonMarketingConsid = gr.Button(CustomPrompts[5])
118
- CustomButtonClassDiagram = gr.Button(CustomPrompts[0])
119
- CustomButtonPydotcode = gr.Button(CustomPrompts[1])
120
- CustomButtonHappyMovieScene = gr.Button(CustomPrompts[2])
121
- CustomButtonClassDiagram.click(custom_generate_response0, inputs=[CustomButtonInput], outputs=MainOutput)
122
- CustomButtonPydotcode.click(custom_generate_response1, inputs=[CustomButtonInput], outputs=MainOutput)
123
- CustomButtonHappyMovieScene.click(custom_generate_response2, inputs=[CustomButtonInput], outputs=MainOutput)
124
- CustomButtonTeardown.click(custom_generate_response3, inputs=[CustomButtonInput], outputs=MainOutput)
125
- CustomButtonManufacture.click(custom_generate_response4, inputs=[CustomButtonInput], outputs=MainOutput)
126
- CustomButtonMarketingConsid.click(custom_generate_response5, inputs=[CustomButtonInput], outputs=MainOutput)
127
 
 
 
 
 
128
 
129
  iface.queue().launch(server_name="0.0.0.0", share=True)
 
65
  error_message = process.stderr.read()
66
  print(f"Error: {error_message}")
67
 
68
+ # def custom_generate_response0(cust_user_message):
69
+ # cust_user_message = CustomPrompts[0] + '\n\n' + cust_user_message + '\n\nClass Diagram:'
70
+ # yield from generate_response(cust_user_message)
71
 
72
+ # def custom_generate_response1(cust_user_message):
73
+ # cust_user_message = CustomPrompts[1] + '\n\n' + cust_user_message + '\n\nPydot Code:'
74
+ # yield from generate_response(cust_user_message)
75
 
76
+ # def custom_generate_response2(cust_user_message):
77
+ # cust_user_message = CustomPrompts[2] + '\n' + cust_user_message + '\n\nScene Details'
78
+ # yield from generate_response(cust_user_message)
79
 
80
+ # def custom_generate_response3(cust_user_message):
81
+ # cust_user_message = CustomPrompts[3] + '\n' + cust_user_message + '\n\nTeardown Details:'
82
+ # yield from generate_response(cust_user_message)
83
 
84
+ # def custom_generate_response4(cust_user_message):
85
+ # cust_user_message = CustomPrompts[4] + '\n' + cust_user_message + '\n\nManufacturing Details:'
86
+ # yield from generate_response(cust_user_message)
87
+
88
+ # def custom_generate_response5(cust_user_message):
89
+ # cust_user_message = CustomPrompts[5] + '\n' + cust_user_message + '\n\nConsiderations:'
90
+ # yield from generate_response(cust_user_message)
91
 
92
+ # CustomPrompts = [
93
+ # "Write a Class Diagram based on the following text:",
94
+ # "Write a Pydot code based on the following text:",
95
+ # "Describe what a standard happy scene in any movie would be planned in great detail, based on the following text:",
96
+ # "Explain a teardown of the product mentioned in the following text:",
97
+ # "Explain the manufacturing of the product mentioned in the following text:",
98
+ # "Explain the marketing considerations of the product mentioned in the following text:",
99
+ # ]
100
+
101
+ # with gr.Blocks() as iface:
102
+ # gr.Interface(
103
+ # fn=generate_response,
104
+ # inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
105
+ # outputs="text",
106
+ # title="Stable LM 2 Zephyr (1.6b) LLama.cpp Interface Test (Inconsistent Performance - 100 tokens in 50 secs or 800+ secs | Over 100 token prompt always slow)",
107
+ # description="No Prompt template used yet (Essentially autocomplete). No Message History for now - Enter your message and get a response.",
108
+ # flagging_dir="/usr/src/app/flagged",
109
+ # )
110
+ # #gr.Interface(fn=generate_response_token_by_token, inputs=gr.Textbox(lines=2, placeholder='Type prompt here...'), outputs="text", description="More Responsive streaming test")
111
+ # with gr.Group():
112
+ # gr.HTML("Test for wrapping generator (Instead of buttons tabs and dropdowns?)")
113
+ # MainOutput = gr.TextArea(placeholder='Output will show here')
114
+ # CustomButtonInput = gr.TextArea(lines=1, placeholder='Prompt goes here')
115
+ # CustomButtonTeardown = gr.Button(CustomPrompts[3])
116
+ # CustomButtonManufacture = gr.Button(CustomPrompts[4])
117
+ # CustomButtonMarketingConsid = gr.Button(CustomPrompts[5])
118
+ # CustomButtonClassDiagram = gr.Button(CustomPrompts[0])
119
+ # CustomButtonPydotcode = gr.Button(CustomPrompts[1])
120
+ # CustomButtonHappyMovieScene = gr.Button(CustomPrompts[2])
121
+ # CustomButtonClassDiagram.click(custom_generate_response0, inputs=[CustomButtonInput], outputs=MainOutput)
122
+ # CustomButtonPydotcode.click(custom_generate_response1, inputs=[CustomButtonInput], outputs=MainOutput)
123
+ # CustomButtonHappyMovieScene.click(custom_generate_response2, inputs=[CustomButtonInput], outputs=MainOutput)
124
+ # CustomButtonTeardown.click(custom_generate_response3, inputs=[CustomButtonInput], outputs=MainOutput)
125
+ # CustomButtonManufacture.click(custom_generate_response4, inputs=[CustomButtonInput], outputs=MainOutput)
126
+ # CustomButtonMarketingConsid.click(custom_generate_response5, inputs=[CustomButtonInput], outputs=MainOutput)
127
+
128
+
129
+ def custom_generate_response(cust_user_message, prompt_index):
130
+ """
131
+ Generates a custom response based on the user message and the selected prompt,
132
+ including a custom ending specific to the prompt.
133
+
134
+ Parameters:
135
+ - cust_user_message: The message input from the user.
136
+ - prompt_index: The index of the custom prompt to use.
137
+ """
138
+ prompt, ending = CustomPrompts[prompt_index] # Unpack the prompt and its ending
139
+ cust_user_message = f"{prompt}\n\n{cust_user_message}\n\n{ending}"
140
  yield from generate_response(cust_user_message)
141
 
142
  CustomPrompts = [
143
+ ("Write a Class Diagram based on the following text:", "Class Diagram:"),
144
+ ("Write a Pydot code based on the following text:", "Pydot Code:"),
145
+ ("Describe what a standard happy scene in any movie would be planned in great detail, based on the following text:", "Scene Details"),
146
+ ("Explain a teardown of the product mentioned in the following text:", "Teardown Details:"),
147
+ ("Explain the manufacturing of the product mentioned in the following text:", "Manufacturing Details:"),
148
+ ("Explain the marketing considerations of the product mentioned in the following text:", "Considerations:"),
149
+ ("Explain the target users considerations of the product mentioned in the following text:", "Target Users Considerations:"),
150
  ]
151
 
152
  with gr.Blocks() as iface:
 
158
  description="No Prompt template used yet (Essentially autocomplete). No Message History for now - Enter your message and get a response.",
159
  flagging_dir="/usr/src/app/flagged",
160
  )
161
+
162
  with gr.Group():
163
  gr.HTML("Test for wrapping generator (Instead of buttons tabs and dropdowns?)")
164
  MainOutput = gr.TextArea(placeholder='Output will show here')
165
  CustomButtonInput = gr.TextArea(lines=1, placeholder='Prompt goes here')
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
+ # Dynamically create buttons and assign actions
168
+ for index, (prompt, _) in enumerate(CustomPrompts):
169
+ button = gr.Button(prompt)
170
+ button.click(custom_generate_response, inputs=[CustomButtonInput, gr.State(index)], outputs=MainOutput)
171
 
172
  iface.queue().launch(server_name="0.0.0.0", share=True)