Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,6 @@ Teknologi:
|
|
| 27 |
"""
|
| 28 |
|
| 29 |
import gradio as gr
|
| 30 |
-
|
| 31 |
from prompt_refiner import PemurniPrompt
|
| 32 |
from variables import api_token, models, meta_prompts, explanation_markdown, metaprompt_list, metaprompt_explanations, examples
|
| 33 |
from custom_css import custom_css
|
|
@@ -38,37 +37,36 @@ class PromptSuiteAI:
|
|
| 38 |
self.prompt_refiner = prompt_refiner
|
| 39 |
default_model = models[-1] if len(models) >= 1 else models[0] if models else None
|
| 40 |
|
| 41 |
-
# with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as self.interface:
|
| 42 |
with gr.Blocks(theme=IndonesiaTheme(), css=custom_css) as self.interface:
|
|
|
|
| 43 |
with gr.Column(elem_classes=["container", "title-container"]):
|
| 44 |
-
# Banner gambar di bagian atas
|
| 45 |
gr.HTML("""
|
| 46 |
<div style='text-align: center;'>
|
| 47 |
-
<img src='https://i.ibb.co/
|
| 48 |
</div>
|
| 49 |
""")
|
| 50 |
-
gr.Markdown("# PromptSuite AI")
|
| 51 |
-
gr.Markdown("### Otomatisasi dan Perbandingan Rekayasa Prompt LLM")
|
| 52 |
-
gr.Markdown("Bandingkan, evaluasi, dan optimasi prompt AI Anda secara praktis dan canggih.")
|
| 53 |
-
# Keterangan platform
|
| 54 |
gr.Markdown(
|
| 55 |
"""
|
| 56 |
<span style='font-size:1.03em; color:#ccc'>
|
| 57 |
-
PromptSuite AI adalah platform rekayasa prompt modern untuk membandingkan, menganalisis,
|
| 58 |
-
dan memperbaiki prompt secara otomatis ataupun manual, berbasis Large Language Model (LLM) open source
|
| 59 |
-
Platform ini dirancang untuk peneliti, praktisi AI, developer, dan siapapun yang ingin mengeksplorasi
|
| 60 |
efek optimasi prompt terhadap kualitas output AI.
|
| 61 |
</span>
|
| 62 |
-
"""
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
# --- KONTENER 2: Input Prompt & Contoh ---
|
| 66 |
with gr.Column(elem_classes=["container", "input-container"]):
|
| 67 |
-
prompt_text = gr.Textbox(label="Tulis prompt Anda (atau kosongkan untuk melihat metaprompt)", lines=5)
|
| 68 |
-
with gr.Accordion("Contoh Prompt", open=False, visible=True):
|
| 69 |
gr.Examples(examples=examples, inputs=[prompt_text])
|
| 70 |
automatic_metaprompt_button = gr.Button(
|
| 71 |
-
"Pilih Otomatis Metode Perbaikan",
|
| 72 |
elem_classes=["button-highlight"]
|
| 73 |
)
|
| 74 |
MetaPrompt_analysis = gr.Markdown()
|
|
@@ -77,22 +75,22 @@ class PromptSuiteAI:
|
|
| 77 |
with gr.Column(elem_classes=["container", "meta-container"]):
|
| 78 |
meta_prompt_choice = gr.Radio(
|
| 79 |
choices=metaprompt_list,
|
| 80 |
-
label="Pilih Metaprompt",
|
| 81 |
value=metaprompt_list[0],
|
| 82 |
elem_classes=["no-background", "radio-group"]
|
| 83 |
)
|
| 84 |
refine_button = gr.Button(
|
| 85 |
-
"Perbaiki Prompt",
|
| 86 |
elem_classes=["button-waiting"]
|
| 87 |
)
|
| 88 |
-
with gr.Accordion("Penjelasan Metaprompt", open=False, visible=True):
|
| 89 |
gr.Markdown(explanation_markdown)
|
| 90 |
|
| 91 |
# --- KONTENER 4: Analisis & Refined Prompt ---
|
| 92 |
with gr.Column(elem_classes=["container", "analysis-container"]):
|
| 93 |
gr.Markdown(" ")
|
| 94 |
prompt_evaluation = gr.Markdown()
|
| 95 |
-
gr.Markdown("### Prompt yang Telah Diperbaiki")
|
| 96 |
refined_prompt = gr.Textbox(
|
| 97 |
label=" ",
|
| 98 |
interactive=True,
|
|
@@ -107,60 +105,58 @@ class PromptSuiteAI:
|
|
| 107 |
apply_model = gr.Dropdown(
|
| 108 |
choices=models,
|
| 109 |
value=default_model,
|
| 110 |
-
label="Pilih Model",
|
| 111 |
container=False,
|
| 112 |
scale=1,
|
| 113 |
min_width=300
|
| 114 |
)
|
| 115 |
apply_button = gr.Button(
|
| 116 |
-
"Uji Prompt ke Model",
|
| 117 |
elem_classes=["button-waiting"]
|
| 118 |
)
|
| 119 |
-
gr.Markdown("### Hasil Pada Model Terpilih")
|
| 120 |
with gr.Tabs(elem_classes=["tabs"]):
|
| 121 |
-
with gr.TabItem("Perbandingan Output", elem_classes=["tabitem"]):
|
| 122 |
with gr.Row(elem_classes=["output-row"]):
|
| 123 |
with gr.Column(scale=1, elem_classes=["comparison-column"]):
|
| 124 |
-
gr.Markdown("### Output Prompt Asli")
|
| 125 |
original_output1 = gr.Markdown(
|
| 126 |
elem_classes=["output-content"],
|
| 127 |
visible=True
|
| 128 |
)
|
| 129 |
with gr.Column(scale=1, elem_classes=["comparison-column"]):
|
| 130 |
-
gr.Markdown("### Output Prompt Diperbaiki")
|
| 131 |
refined_output1 = gr.Markdown(
|
| 132 |
elem_classes=["output-content"],
|
| 133 |
visible=True
|
| 134 |
)
|
| 135 |
-
with gr.TabItem("Output Prompt Asli", elem_classes=["tabitem"]):
|
| 136 |
with gr.Row(elem_classes=["output-row"]):
|
| 137 |
with gr.Column(scale=1, elem_classes=["comparison-column"]):
|
| 138 |
-
gr.Markdown("### Output Prompt Asli")
|
| 139 |
original_output = gr.Markdown(
|
| 140 |
elem_classes=["output-content"],
|
| 141 |
visible=True
|
| 142 |
)
|
| 143 |
-
with gr.TabItem("Output Prompt Diperbaiki", elem_classes=["tabitem"]):
|
| 144 |
with gr.Row(elem_classes=["output-row"]):
|
| 145 |
with gr.Column(scale=1, elem_classes=["comparison-column"]):
|
| 146 |
-
gr.Markdown("### Output Prompt Diperbaiki")
|
| 147 |
refined_output = gr.Markdown(
|
| 148 |
elem_classes=["output-content"],
|
| 149 |
visible=True
|
| 150 |
)
|
| 151 |
-
with gr.Accordion("Respons JSON Lengkap", open=False, visible=True):
|
| 152 |
full_response_json = gr.JSON()
|
| 153 |
|
| 154 |
# ======================= EVENT HANDLER / JS ==========================
|
| 155 |
|
| 156 |
-
# Handler untuk otomatis memilih metaprompt
|
| 157 |
def automatic_metaprompt(prompt: str):
|
| 158 |
if not prompt.strip():
|
| 159 |
return "Silakan masukkan prompt untuk dianalisis.", None
|
| 160 |
metaprompt_analysis, recommended_key = self.prompt_refiner.automatic_metaprompt(prompt)
|
| 161 |
return metaprompt_analysis, recommended_key
|
| 162 |
|
| 163 |
-
# Handler untuk refine prompt manual
|
| 164 |
def refine_prompt(prompt: str, meta_prompt_choice: str):
|
| 165 |
if not prompt.strip():
|
| 166 |
return ("Tidak ada prompt.", "", "", {})
|
|
@@ -172,7 +168,6 @@ class PromptSuiteAI:
|
|
| 172 |
result[3] # Full JSON response
|
| 173 |
)
|
| 174 |
|
| 175 |
-
# Handler untuk menguji prompt pada model
|
| 176 |
def apply_prompts(original_prompt: str, refined_prompt_: str, model: str):
|
| 177 |
if not original_prompt or not refined_prompt_:
|
| 178 |
return (
|
|
@@ -292,7 +287,6 @@ class PromptSuiteAI:
|
|
| 292 |
"""
|
| 293 |
)
|
| 294 |
|
| 295 |
-
# Reset ketika input berubah
|
| 296 |
prompt_text.change(
|
| 297 |
fn=lambda: None,
|
| 298 |
inputs=None,
|
|
@@ -324,7 +318,6 @@ class PromptSuiteAI:
|
|
| 324 |
"""Jalankan antarmuka PromptSuite AI"""
|
| 325 |
self.interface.launch(share=share)
|
| 326 |
|
| 327 |
-
|
| 328 |
if __name__ == '__main__':
|
| 329 |
prompt_refiner = PemurniPrompt(api_token, meta_prompts, metaprompt_explanations)
|
| 330 |
app = PromptSuiteAI(prompt_refiner, custom_css)
|
|
|
|
| 27 |
"""
|
| 28 |
|
| 29 |
import gradio as gr
|
|
|
|
| 30 |
from prompt_refiner import PemurniPrompt
|
| 31 |
from variables import api_token, models, meta_prompts, explanation_markdown, metaprompt_list, metaprompt_explanations, examples
|
| 32 |
from custom_css import custom_css
|
|
|
|
| 37 |
self.prompt_refiner = prompt_refiner
|
| 38 |
default_model = models[-1] if len(models) >= 1 else models[0] if models else None
|
| 39 |
|
|
|
|
| 40 |
with gr.Blocks(theme=IndonesiaTheme(), css=custom_css) as self.interface:
|
| 41 |
+
# --- HEADER & TITLE ---
|
| 42 |
with gr.Column(elem_classes=["container", "title-container"]):
|
|
|
|
| 43 |
gr.HTML("""
|
| 44 |
<div style='text-align: center;'>
|
| 45 |
+
<img src='https://i.ibb.co.com/ynqKvrr/banner-pulid.jpg' alt='Banner' style='width: 100%; max-width:820px; height: auto; border-radius:16px; box-shadow:0 2px 12px 0 rgba(30,30,30,0.12); margin-bottom:0.7em;'/>
|
| 46 |
</div>
|
| 47 |
""")
|
| 48 |
+
gr.Markdown("# 🚀 PromptSuite AI")
|
| 49 |
+
gr.Markdown("### 🤖 Otomatisasi dan Perbandingan Rekayasa Prompt LLM")
|
| 50 |
+
gr.Markdown("🔍 Bandingkan, evaluasi, dan optimasi prompt AI Anda secara praktis dan canggih.")
|
|
|
|
| 51 |
gr.Markdown(
|
| 52 |
"""
|
| 53 |
<span style='font-size:1.03em; color:#ccc'>
|
| 54 |
+
✨ <b>PromptSuite AI</b> adalah platform rekayasa prompt modern untuk membandingkan, menganalisis,
|
| 55 |
+
dan memperbaiki prompt secara otomatis ataupun manual, berbasis Large Language Model (LLM) open source.<br>
|
| 56 |
+
💡 Platform ini dirancang untuk peneliti, praktisi AI, developer, dan siapapun yang ingin mengeksplorasi
|
| 57 |
efek optimasi prompt terhadap kualitas output AI.
|
| 58 |
</span>
|
| 59 |
+
""",
|
| 60 |
+
unsafe_allow_html=True
|
| 61 |
)
|
| 62 |
|
| 63 |
# --- KONTENER 2: Input Prompt & Contoh ---
|
| 64 |
with gr.Column(elem_classes=["container", "input-container"]):
|
| 65 |
+
prompt_text = gr.Textbox(label="✏️ Tulis prompt Anda (atau kosongkan untuk melihat metaprompt)", lines=5)
|
| 66 |
+
with gr.Accordion("📋 Contoh Prompt", open=False, visible=True):
|
| 67 |
gr.Examples(examples=examples, inputs=[prompt_text])
|
| 68 |
automatic_metaprompt_button = gr.Button(
|
| 69 |
+
"🔮 Pilih Otomatis Metode Perbaikan",
|
| 70 |
elem_classes=["button-highlight"]
|
| 71 |
)
|
| 72 |
MetaPrompt_analysis = gr.Markdown()
|
|
|
|
| 75 |
with gr.Column(elem_classes=["container", "meta-container"]):
|
| 76 |
meta_prompt_choice = gr.Radio(
|
| 77 |
choices=metaprompt_list,
|
| 78 |
+
label="🛠️ Pilih Metaprompt",
|
| 79 |
value=metaprompt_list[0],
|
| 80 |
elem_classes=["no-background", "radio-group"]
|
| 81 |
)
|
| 82 |
refine_button = gr.Button(
|
| 83 |
+
"✨ Perbaiki Prompt",
|
| 84 |
elem_classes=["button-waiting"]
|
| 85 |
)
|
| 86 |
+
with gr.Accordion("ℹ️ Penjelasan Metaprompt", open=False, visible=True):
|
| 87 |
gr.Markdown(explanation_markdown)
|
| 88 |
|
| 89 |
# --- KONTENER 4: Analisis & Refined Prompt ---
|
| 90 |
with gr.Column(elem_classes=["container", "analysis-container"]):
|
| 91 |
gr.Markdown(" ")
|
| 92 |
prompt_evaluation = gr.Markdown()
|
| 93 |
+
gr.Markdown("### ✨ Prompt yang Telah Diperbaiki")
|
| 94 |
refined_prompt = gr.Textbox(
|
| 95 |
label=" ",
|
| 96 |
interactive=True,
|
|
|
|
| 105 |
apply_model = gr.Dropdown(
|
| 106 |
choices=models,
|
| 107 |
value=default_model,
|
| 108 |
+
label="🧠 Pilih Model",
|
| 109 |
container=False,
|
| 110 |
scale=1,
|
| 111 |
min_width=300
|
| 112 |
)
|
| 113 |
apply_button = gr.Button(
|
| 114 |
+
"⚡ Uji Prompt ke Model",
|
| 115 |
elem_classes=["button-waiting"]
|
| 116 |
)
|
| 117 |
+
gr.Markdown("### 📝 Hasil Pada Model Terpilih")
|
| 118 |
with gr.Tabs(elem_classes=["tabs"]):
|
| 119 |
+
with gr.TabItem("📊 Perbandingan Output", elem_classes=["tabitem"]):
|
| 120 |
with gr.Row(elem_classes=["output-row"]):
|
| 121 |
with gr.Column(scale=1, elem_classes=["comparison-column"]):
|
| 122 |
+
gr.Markdown("### 🔡 Output Prompt Asli")
|
| 123 |
original_output1 = gr.Markdown(
|
| 124 |
elem_classes=["output-content"],
|
| 125 |
visible=True
|
| 126 |
)
|
| 127 |
with gr.Column(scale=1, elem_classes=["comparison-column"]):
|
| 128 |
+
gr.Markdown("### ✨ Output Prompt Diperbaiki")
|
| 129 |
refined_output1 = gr.Markdown(
|
| 130 |
elem_classes=["output-content"],
|
| 131 |
visible=True
|
| 132 |
)
|
| 133 |
+
with gr.TabItem("🔡 Output Prompt Asli", elem_classes=["tabitem"]):
|
| 134 |
with gr.Row(elem_classes=["output-row"]):
|
| 135 |
with gr.Column(scale=1, elem_classes=["comparison-column"]):
|
| 136 |
+
gr.Markdown("### 🔡 Output Prompt Asli")
|
| 137 |
original_output = gr.Markdown(
|
| 138 |
elem_classes=["output-content"],
|
| 139 |
visible=True
|
| 140 |
)
|
| 141 |
+
with gr.TabItem("✨ Output Prompt Diperbaiki", elem_classes=["tabitem"]):
|
| 142 |
with gr.Row(elem_classes=["output-row"]):
|
| 143 |
with gr.Column(scale=1, elem_classes=["comparison-column"]):
|
| 144 |
+
gr.Markdown("### ✨ Output Prompt Diperbaiki")
|
| 145 |
refined_output = gr.Markdown(
|
| 146 |
elem_classes=["output-content"],
|
| 147 |
visible=True
|
| 148 |
)
|
| 149 |
+
with gr.Accordion("🧾 Respons JSON Lengkap", open=False, visible=True):
|
| 150 |
full_response_json = gr.JSON()
|
| 151 |
|
| 152 |
# ======================= EVENT HANDLER / JS ==========================
|
| 153 |
|
|
|
|
| 154 |
def automatic_metaprompt(prompt: str):
|
| 155 |
if not prompt.strip():
|
| 156 |
return "Silakan masukkan prompt untuk dianalisis.", None
|
| 157 |
metaprompt_analysis, recommended_key = self.prompt_refiner.automatic_metaprompt(prompt)
|
| 158 |
return metaprompt_analysis, recommended_key
|
| 159 |
|
|
|
|
| 160 |
def refine_prompt(prompt: str, meta_prompt_choice: str):
|
| 161 |
if not prompt.strip():
|
| 162 |
return ("Tidak ada prompt.", "", "", {})
|
|
|
|
| 168 |
result[3] # Full JSON response
|
| 169 |
)
|
| 170 |
|
|
|
|
| 171 |
def apply_prompts(original_prompt: str, refined_prompt_: str, model: str):
|
| 172 |
if not original_prompt or not refined_prompt_:
|
| 173 |
return (
|
|
|
|
| 287 |
"""
|
| 288 |
)
|
| 289 |
|
|
|
|
| 290 |
prompt_text.change(
|
| 291 |
fn=lambda: None,
|
| 292 |
inputs=None,
|
|
|
|
| 318 |
"""Jalankan antarmuka PromptSuite AI"""
|
| 319 |
self.interface.launch(share=share)
|
| 320 |
|
|
|
|
| 321 |
if __name__ == '__main__':
|
| 322 |
prompt_refiner = PemurniPrompt(api_token, meta_prompts, metaprompt_explanations)
|
| 323 |
app = PromptSuiteAI(prompt_refiner, custom_css)
|