Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,60 +104,105 @@ class GradioInterface:
|
|
| 104 |
def __init__(self, prompt_refiner: PromptRefiner):
|
| 105 |
self.prompt_refiner = prompt_refiner
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
gr.Markdown("# PROMPT++")
|
| 109 |
gr.Markdown("### Automating Prompt Engineering by Refining your Prompts")
|
| 110 |
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.")
|
| 111 |
|
| 112 |
-
|
| 113 |
-
with gr.
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
with gr.Accordion("Full Response JSON", open=False,visible=False):
|
| 130 |
full_response_json = gr.JSON()
|
| 131 |
|
| 132 |
-
|
| 133 |
refine_button.click(
|
| 134 |
fn=self.refine_prompt,
|
| 135 |
inputs=[prompt_text, meta_prompt_choice],
|
| 136 |
outputs=[analysis_evaluation, refined_prompt, explanation_of_refinements, full_response_json]
|
| 137 |
)
|
| 138 |
-
gr.Markdown("## See MetaPrompt Impact")
|
| 139 |
-
with gr.Row():
|
| 140 |
-
apply_model = gr.Dropdown(
|
| 141 |
-
[
|
| 142 |
-
"Qwen/Qwen2.5-72B-Instruct",
|
| 143 |
-
"meta-llama/Meta-Llama-3-70B-Instruct",
|
| 144 |
-
"meta-llama/Llama-3.1-8B-Instruct",
|
| 145 |
-
"NousResearch/Hermes-3-Llama-3.1-8B",
|
| 146 |
-
"HuggingFaceH4/zephyr-7b-alpha",
|
| 147 |
-
"meta-llama/Llama-2-7b-chat-hf",
|
| 148 |
-
"microsoft/Phi-3.5-mini-instruct"
|
| 149 |
-
],
|
| 150 |
-
value="meta-llama/Meta-Llama-3-70B-Instruct",
|
| 151 |
-
label="Choose the Model to apply to the prompts (the one you will used)"
|
| 152 |
-
)
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
original_output = gr.Markdown(label="Original Prompt Output")
|
| 159 |
-
|
| 160 |
-
#gr.Markdown("### Refined Prompt Output")
|
| 161 |
refined_output = gr.Markdown(label="Refined Prompt Output")
|
| 162 |
|
| 163 |
apply_button.click(
|
|
@@ -165,6 +210,8 @@ class GradioInterface:
|
|
| 165 |
inputs=[prompt_text, refined_prompt, apply_model],
|
| 166 |
outputs=[original_output, refined_output]
|
| 167 |
)
|
|
|
|
|
|
|
| 168 |
with gr.Accordion("Examples", open=True):
|
| 169 |
gr.Examples(
|
| 170 |
examples=[
|
|
@@ -182,6 +229,7 @@ class GradioInterface:
|
|
| 182 |
inputs=[prompt_text, meta_prompt_choice]
|
| 183 |
)
|
| 184 |
|
|
|
|
| 185 |
def refine_prompt(self, prompt: str, meta_prompt_choice: str) -> tuple:
|
| 186 |
input_data = PromptInput(text=prompt, meta_prompt_choice=meta_prompt_choice)
|
| 187 |
result = self.prompt_refiner.refine_prompt(input_data)
|
|
|
|
| 104 |
def __init__(self, prompt_refiner: PromptRefiner):
|
| 105 |
self.prompt_refiner = prompt_refiner
|
| 106 |
|
| 107 |
+
# Define custom CSS for containers
|
| 108 |
+
custom_css = """
|
| 109 |
+
.input-container, .output-container {
|
| 110 |
+
border: 2px solid var(--primary-500);
|
| 111 |
+
border-radius: 10px;
|
| 112 |
+
padding: 20px;
|
| 113 |
+
margin: 15px;
|
| 114 |
+
background: var(--background-fill-primary);
|
| 115 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 116 |
+
position: relative;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.input-container::before {
|
| 120 |
+
content: 'Input Section';
|
| 121 |
+
position: absolute;
|
| 122 |
+
top: -12px;
|
| 123 |
+
left: 20px;
|
| 124 |
+
background: var(--background-fill-primary);
|
| 125 |
+
padding: 0 10px;
|
| 126 |
+
color: var(--primary-500);
|
| 127 |
+
font-weight: bold;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.output-container::before {
|
| 131 |
+
content: 'Output Section';
|
| 132 |
+
position: absolute;
|
| 133 |
+
top: -12px;
|
| 134 |
+
left: 20px;
|
| 135 |
+
background: var(--background-fill-primary);
|
| 136 |
+
padding: 0 10px;
|
| 137 |
+
color: var(--primary-500);
|
| 138 |
+
font-weight: bold;
|
| 139 |
+
}
|
| 140 |
+
"""
|
| 141 |
+
|
| 142 |
+
with gr.Blocks(css=custom_css) as self.interface:
|
| 143 |
gr.Markdown("# PROMPT++")
|
| 144 |
gr.Markdown("### Automating Prompt Engineering by Refining your Prompts")
|
| 145 |
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.")
|
| 146 |
|
| 147 |
+
# Input Container
|
| 148 |
+
with gr.Column(elem_classes="input-container"):
|
| 149 |
+
gr.Markdown("## Refine Prompt")
|
| 150 |
+
with gr.Row():
|
| 151 |
+
prompt_text = gr.Textbox(label="Type the prompt (or let it empty to see metaprompt)")
|
| 152 |
+
with gr.Accordion("Meta Prompt explanation", open=False):
|
| 153 |
+
gr.Markdown(explanation_markdown)
|
| 154 |
+
with gr.Row():
|
| 155 |
+
meta_prompt_choice = gr.Radio(
|
| 156 |
+
["star","done","physics","morphosis", "verse", "phor","bolism","math","arpe"],
|
| 157 |
+
label="Choose Meta Prompt",
|
| 158 |
+
value="star"
|
| 159 |
+
)
|
| 160 |
+
refine_button = gr.Button("Refine Prompt")
|
| 161 |
+
|
| 162 |
+
# Output Container
|
| 163 |
+
with gr.Column(elem_classes="output-container"):
|
| 164 |
+
with gr.Row():
|
| 165 |
+
gr.Markdown("### Initial prompt analysis")
|
| 166 |
+
with gr.Column():
|
| 167 |
+
analysis_evaluation = gr.Markdown(label="Analysis and Evaluation")
|
| 168 |
+
gr.Markdown("### Refined Prompt")
|
| 169 |
+
refined_prompt = gr.Textbox(label="Refined Prompt")
|
| 170 |
+
gr.Markdown("### Explanation of Refinements")
|
| 171 |
+
explanation_of_refinements = gr.Markdown(label="Explanation of Refinements")
|
| 172 |
|
| 173 |
+
with gr.Accordion("Full Response JSON", open=False, visible=False):
|
| 174 |
full_response_json = gr.JSON()
|
| 175 |
|
|
|
|
| 176 |
refine_button.click(
|
| 177 |
fn=self.refine_prompt,
|
| 178 |
inputs=[prompt_text, meta_prompt_choice],
|
| 179 |
outputs=[analysis_evaluation, refined_prompt, explanation_of_refinements, full_response_json]
|
| 180 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
+
# Model Application Section
|
| 183 |
+
with gr.Column(elem_classes="input-container"):
|
| 184 |
+
gr.Markdown("## See MetaPrompt Impact")
|
| 185 |
+
with gr.Row():
|
| 186 |
+
apply_model = gr.Dropdown(
|
| 187 |
+
[
|
| 188 |
+
"Qwen/Qwen2.5-72B-Instruct",
|
| 189 |
+
"meta-llama/Meta-Llama-3-70B-Instruct",
|
| 190 |
+
"meta-llama/Llama-3.1-8B-Instruct",
|
| 191 |
+
"NousResearch/Hermes-3-Llama-3.1-8B",
|
| 192 |
+
"HuggingFaceH4/zephyr-7b-alpha",
|
| 193 |
+
"meta-llama/Llama-2-7b-chat-hf",
|
| 194 |
+
"microsoft/Phi-3.5-mini-instruct"
|
| 195 |
+
],
|
| 196 |
+
value="meta-llama/Meta-Llama-3-70B-Instruct",
|
| 197 |
+
label="Choose the Model to apply to the prompts (the one you will used)"
|
| 198 |
+
)
|
| 199 |
+
apply_button = gr.Button("Apply MetaPrompt")
|
| 200 |
+
|
| 201 |
+
# Results Container
|
| 202 |
+
with gr.Column(elem_classes="output-container"):
|
| 203 |
+
with gr.Tab("Original Prompt Output"):
|
| 204 |
original_output = gr.Markdown(label="Original Prompt Output")
|
| 205 |
+
with gr.Tab("Refined Prompt Output"):
|
|
|
|
| 206 |
refined_output = gr.Markdown(label="Refined Prompt Output")
|
| 207 |
|
| 208 |
apply_button.click(
|
|
|
|
| 210 |
inputs=[prompt_text, refined_prompt, apply_model],
|
| 211 |
outputs=[original_output, refined_output]
|
| 212 |
)
|
| 213 |
+
|
| 214 |
+
# Examples Section
|
| 215 |
with gr.Accordion("Examples", open=True):
|
| 216 |
gr.Examples(
|
| 217 |
examples=[
|
|
|
|
| 229 |
inputs=[prompt_text, meta_prompt_choice]
|
| 230 |
)
|
| 231 |
|
| 232 |
+
# Rest of the class methods remain the same
|
| 233 |
def refine_prompt(self, prompt: str, meta_prompt_choice: str) -> tuple:
|
| 234 |
input_data = PromptInput(text=prompt, meta_prompt_choice=meta_prompt_choice)
|
| 235 |
result = self.prompt_refiner.refine_prompt(input_data)
|