Spaces:
Paused
Paused
Rename main.py -> app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
from config import Models
|
| 5 |
+
from generator import generate
|
| 6 |
+
|
| 7 |
+
MODELS = {
|
| 8 |
+
"GPT-5 Nano (OpenAI)": Models.GPT_5_NANO,
|
| 9 |
+
"GPT-5.4 Mini (OpenAI)": Models.GPT_5_4_MINI,
|
| 10 |
+
"Claude Haiku 4.5 (Anthropic)": Models.CLAUDE_HAIKU_4_5,
|
| 11 |
+
"Gemini 2.5 Flash Lite (Google)": Models.GEMINI_2_5_FLASH_LITE,
|
| 12 |
+
"Qwen3 8B (HuggingFace)": Models.QWEN3_8B,
|
| 13 |
+
"Qwen3 4B (HuggingFace)": Models.QWEN3_4B,
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def run_generate(model_name: str, prompt: str, num_records: int):
|
| 18 |
+
if not prompt.strip():
|
| 19 |
+
raise gr.Error("Please enter a prompt.")
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
raw = generate(prompt=prompt, num_records=num_records, model_config=MODELS[model_name])
|
| 23 |
+
except Exception as e:
|
| 24 |
+
raise gr.Error(f"Generation failed: {e}")
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
return json.dumps(json.loads(raw), indent=2), gr.update(visible=True)
|
| 28 |
+
except json.JSONDecodeError:
|
| 29 |
+
return raw, gr.update(visible=True)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def download_json(output: str):
|
| 33 |
+
path = "/tmp/dataset.json"
|
| 34 |
+
with open(path, "w") as f:
|
| 35 |
+
f.write(output)
|
| 36 |
+
return path
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def build_ui() -> gr.Blocks:
|
| 40 |
+
with gr.Blocks(title="Synthetic Dataset Generator") as app:
|
| 41 |
+
gr.Markdown("# 🧪 Synthetic Dataset Generator")
|
| 42 |
+
|
| 43 |
+
with gr.Row():
|
| 44 |
+
with gr.Column(scale=1):
|
| 45 |
+
model_dropdown = gr.Dropdown(
|
| 46 |
+
choices=list(MODELS.keys()),
|
| 47 |
+
value="GPT-5 Nano (OpenAI)",
|
| 48 |
+
label="Model",
|
| 49 |
+
)
|
| 50 |
+
num_records = gr.Slider(
|
| 51 |
+
minimum=1, maximum=500, value=20, step=1,
|
| 52 |
+
label="Number of Records",
|
| 53 |
+
)
|
| 54 |
+
prompt = gr.Textbox(
|
| 55 |
+
lines=8,
|
| 56 |
+
placeholder=(
|
| 57 |
+
"Describe the dataset you want to generate.\n\n"
|
| 58 |
+
"Example:\n"
|
| 59 |
+
"Generate customer support tickets with fields:\n"
|
| 60 |
+
"- ticket_id (string)\n"
|
| 61 |
+
"- issue (string)\n"
|
| 62 |
+
"- priority (low | medium | high)\n"
|
| 63 |
+
"- resolved (boolean)"
|
| 64 |
+
),
|
| 65 |
+
label="Dataset Prompt",
|
| 66 |
+
)
|
| 67 |
+
generate_btn = gr.Button("Generate", variant="primary")
|
| 68 |
+
|
| 69 |
+
with gr.Column(scale=1):
|
| 70 |
+
output = gr.Code(
|
| 71 |
+
label="Output",
|
| 72 |
+
language="json",
|
| 73 |
+
interactive=False,
|
| 74 |
+
)
|
| 75 |
+
download_btn = gr.DownloadButton(
|
| 76 |
+
label="Download JSON",
|
| 77 |
+
visible=False,
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
generate_btn.click(
|
| 81 |
+
fn=run_generate,
|
| 82 |
+
inputs=[model_dropdown, prompt, num_records],
|
| 83 |
+
outputs=[output, download_btn],
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
output.change(
|
| 87 |
+
fn=download_json,
|
| 88 |
+
inputs=[output],
|
| 89 |
+
outputs=[download_btn],
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
return app
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
build_ui().launch()
|
main.py
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
def main():
|
| 2 |
-
print("Hello from dataset-generator!")
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
if __name__ == "__main__":
|
| 6 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|