yxmnjxzx commited on
Commit
52caa46
·
verified ·
1 Parent(s): f477fb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -29
app.py CHANGED
@@ -112,11 +112,14 @@ class GradioInterface:
112
 
113
  with gr.Blocks() as self.interface:
114
  gr.Markdown("# PROMPT++")
115
- gr.Markdown("### Refine your Prompts: Learn how to generate an improved version of your prompts")
116
- gr.Markdown("Enter a main idea for a prompt, choose a meta prompt, and the model will attempt to generate an improved version.")
117
 
 
118
  with gr.Row():
119
- prompt_text = gr.Textbox(label="Type the prompt here")
 
 
120
  with gr.Row():
121
  meta_prompt_choice = gr.Radio(["superstar", "star", "done", "physics", "morphosis", "verse", "phor","bolism"], label="Choose Meta Prompt", value="morphosis")
122
  refine_button = gr.Button("Refine Prompt")
@@ -128,15 +131,17 @@ class GradioInterface:
128
  refined_prompt = gr.Textbox(label="Refined Prompt")
129
  gr.Markdown("### Explanation of Refinements")
130
  explanation_of_refinements = gr.Markdown(label="Explanation of Refinements")
131
-
132
- with gr.Accordion("Full Response JSON", open=False):
133
  full_response_json = gr.JSON()
134
 
 
135
  refine_button.click(
136
  fn=self.refine_prompt,
137
  inputs=[prompt_text, meta_prompt_choice],
138
  outputs=[analysis_evaluation, refined_prompt, explanation_of_refinements, full_response_json]
139
  )
 
140
  with gr.Row():
141
  apply_model = gr.Dropdown(
142
  [
@@ -151,37 +156,37 @@ class GradioInterface:
151
  label="Choose the Model to apply prompts"
152
  )
153
  # apply_model=gr.Dropdown(["gpt-4o",'gpt-4-turbo'], value="gpt-4o", label="Model"),
154
- apply_button = gr.Button("Apply Prompts")
155
-
156
- with gr.Row():
157
- with gr.Column():
158
- gr.Markdown("### Original Prompt Output")
159
  original_output = gr.Markdown(label="Original Prompt Output")
160
- with gr.Column():
161
- gr.Markdown("### Refined Prompt Output")
162
  refined_output = gr.Markdown(label="Refined Prompt Output")
163
 
164
  apply_button.click(
165
  fn=self.apply_prompts,
166
  inputs=[prompt_text, refined_prompt, apply_model],
167
- outputs=[original_output, refined_output]
168
  )
169
 
170
- gr.Examples(
171
- examples=[
172
- ["Tell me about that guy who invented the light bulb", "physics"],
173
- ["Explain the universe.", "star"],
174
- ["What's the population of New York City and how tall is the Empire State Building and who was the first mayor?", "morphosis"],
175
- ["List American presidents.", "verse"],
176
- ["Write a story.", "bolism"],
177
- ["Explain why the experiment failed.", "morphosis"],
178
- ["Is nuclear energy good?", "verse"],
179
- ["How does a computer work?", "phor"],
180
- ["How to make money fast?", "done"],
181
- ["how can you prove IT0's lemma in stochastic calculus ?", "superstar"],
182
- ],
183
- inputs=[prompt_text, meta_prompt_choice]
184
- )
 
185
 
186
 
187
  def refine_prompt(self, prompt: str, meta_prompt_choice: str) -> tuple:
@@ -202,7 +207,20 @@ class GradioInterface:
202
 
203
  def launch(self, share=False):
204
  self.interface.launch(share=share)
205
-
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  # Main code to run the application
207
  if __name__ == '__main__':
208
  api_key = os.getenv('GROQ_API_KEY')
 
112
 
113
  with gr.Blocks() as self.interface:
114
  gr.Markdown("# PROMPT++")
115
+ gr.Markdown("### Automating Prompt Engineering by Refining your Prompts")
116
+ gr.Markdown("Learn how to generate an improved version of your prompts. Enter a main idea for a prompt, choose a meta prompt, and the model will attempt to generate an improved version.")
117
 
118
+ gr.Markdown("## Refine Prompt")
119
  with gr.Row():
120
+ prompt_text = gr.Textbox(label="Type the prompt (or let it empty to see metaprompt)")
121
+ with gr.Accordion("Meta Prompt explanation", open=False):
122
+ gr.Markdown(explanation_markdown)
123
  with gr.Row():
124
  meta_prompt_choice = gr.Radio(["superstar", "star", "done", "physics", "morphosis", "verse", "phor","bolism"], label="Choose Meta Prompt", value="morphosis")
125
  refine_button = gr.Button("Refine Prompt")
 
131
  refined_prompt = gr.Textbox(label="Refined Prompt")
132
  gr.Markdown("### Explanation of Refinements")
133
  explanation_of_refinements = gr.Markdown(label="Explanation of Refinements")
134
+
135
+ with gr.Accordion("Full Response JSON", open=False,visible=False):
136
  full_response_json = gr.JSON()
137
 
138
+
139
  refine_button.click(
140
  fn=self.refine_prompt,
141
  inputs=[prompt_text, meta_prompt_choice],
142
  outputs=[analysis_evaluation, refined_prompt, explanation_of_refinements, full_response_json]
143
  )
144
+ gr.Markdown("## See MetaPrompt Impact")
145
  with gr.Row():
146
  apply_model = gr.Dropdown(
147
  [
 
156
  label="Choose the Model to apply prompts"
157
  )
158
  # apply_model=gr.Dropdown(["gpt-4o",'gpt-4-turbo'], value="gpt-4o", label="Model"),
159
+ apply_button = gr.Button("Apply MetaPrompt")
160
+
161
+ with gr.Tab("Original Prompt Output"):
162
+ # gr.Markdown("### Original Prompt Output")
 
163
  original_output = gr.Markdown(label="Original Prompt Output")
164
+ with gr.Tab("Refined Prompt Output"):
165
+ #gr.Markdown("### Refined Prompt Output")
166
  refined_output = gr.Markdown(label="Refined Prompt Output")
167
 
168
  apply_button.click(
169
  fn=self.apply_prompts,
170
  inputs=[prompt_text, refined_prompt, apply_model],
171
+ outputs=[original_output, refined_output]
172
  )
173
 
174
+ with gr.Accordion("Examples", open=True):
175
+ gr.Examples(
176
+ examples=[
177
+ ["Write a story on the end of prompt engineering replaced by an Ai specialized in refining prompts.", "star"],
178
+ ["Tell me about that guy who invented the light bulb", "physics"],
179
+ ["Explain the universe.", "star"],
180
+ ["What's the population of New York City and how tall is the Empire State Building and who was the first mayor?", "morphosis"],
181
+ ["List American presidents.", "verse"],
182
+ ["Explain why the experiment failed.", "morphosis"],
183
+ ["Is nuclear energy good?", "verse"],
184
+ ["How does a computer work?", "phor"],
185
+ ["How to make money fast?", "done"],
186
+ ["how can you prove IT0's lemma in stochastic calculus ?", "superstar"],
187
+ ],
188
+ inputs=[prompt_text, meta_prompt_choice]
189
+ )
190
 
191
 
192
  def refine_prompt(self, prompt: str, meta_prompt_choice: str) -> tuple:
 
207
 
208
  def launch(self, share=False):
209
  self.interface.launch(share=share)
210
+
211
+ metaprompt_explanations = {
212
+ "star": "Use ECHO when you need a comprehensive, multi-stage approach for complex prompts. It's ideal for tasks requiring in-depth analysis, exploration of multiple alternatives, and synthesis of ideas. Choose this over others when you have time for a thorough refinement process and need to consider various aspects of the prompt.",
213
+ "superstar": "Use advanced ECHO when you need a comprehensive, multi-stage approach for complex prompts. It's ideal for tasks requiring in-depth analysis, exploration of multiple alternatives, and synthesis of ideas. Choose this over others when you have time for a thorough refinement process and need to consider various aspects of the prompt.",
214
+ "done": "Opt for this when you want a structured approach with emphasis on role-playing and advanced techniques. It's particularly useful for tasks that benefit from diverse perspectives and complex reasoning. Prefer this over 'physics' when you need a more detailed, step-by-step refinement process.",
215
+ "physics": "Select this when you need a balance between structure and advanced techniques, with a focus on role-playing. It's similar to 'done' but may be more suitable for scientific or technical prompts. Choose this over 'done' for a slightly less complex approach.",
216
+ "morphosis": "Use this simplified approach for straightforward prompts or when time is limited. It focuses on essential improvements without complex techniques. Prefer this over other methods when you need quick, clear refinements without extensive analysis.",
217
+ "verse": "Choose this method when you need to analyze and improve a prompt's strengths and weaknesses, with a focus on information flow. It's particularly useful for enhancing the logical structure of prompts. Use this over 'morphosis' when you need more depth but less complexity than 'star'.",
218
+ "phor": "Employ this advanced approach when you need to combine multiple prompt engineering techniques. It's ideal for complex tasks requiring both clarity and sophisticated prompting methods. Select this over 'star' when you want a more flexible, technique-focused approach.",
219
+ "bolism": "Utilize this method when working with autoregressive language models and when the task requires careful reasoning before conclusions. It's best for prompts that need detailed output formatting. Choose this over others when the prompt's structure and reasoning order are crucial."
220
+ }
221
+
222
+ explanation_markdown = "".join([f"- **{key}**: {value}\n" for key, value in metaprompt_explanations.items()])
223
+
224
  # Main code to run the application
225
  if __name__ == '__main__':
226
  api_key = os.getenv('GROQ_API_KEY')