Akhmad123 commited on
Commit
324f455
·
verified ·
1 Parent(s): 4e55de2

Upload 5 files

Browse files
Files changed (5) hide show
  1. README.md +27 -13
  2. app.py +114 -0
  3. requirements.txt +1 -0
  4. templates.json +17 -0
  5. templates_extra.md +29 -0
README.md CHANGED
@@ -1,13 +1,27 @@
1
- ---
2
- title: AIPromptLab
3
- emoji: 🌍
4
- colorFrom: indigo
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 6.14.0
8
- python_version: '3.13'
9
- app_file: app.py
10
- pinned: false
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AI Prompt Generator Gratis
2
+
3
+ Aplikasi web sederhana untuk menghasilkan prompt siap pakai berbasis template. Gratis dan mudah di-deploy ke Hugging Face Spaces atau dijalankan lokal.
4
+
5
+ ## Cara pakai singkat
6
+ 1. Isi form Goal, pilih tipe (text/image/code).
7
+ 2. Klik Generate.
8
+ 3. Salin prompt dari JSON dan gunakan di model tujuan.
9
+
10
+ ## Deploy ke Hugging Face Spaces
11
+ 1. Buat akun Hugging Face.
12
+ 2. Buat Space baru dengan runtime Gradio.
13
+ 3. Upload semua file repo.
14
+ 4. Tunggu build selesai, aplikasi akan tersedia publik.
15
+
16
+ ## Jalankan lokal
17
+ 1. `python -m venv venv && source venv/bin/activate` (Linux/Mac) atau `venv\\Scripts\\activate` (Windows)
18
+ 2. `pip install -r requirements.txt`
19
+ 3. `python app.py`
20
+ 4. Buka `http://localhost:7860`
21
+
22
+ ## Expose ke internet (opsional)
23
+ Gunakan ngrok atau layanan tunneling lain untuk membuat URL publik.
24
+
25
+ ## Menambahkan template
26
+ Edit `templates.json` untuk menambah atau mengubah template.
27
+
app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ import json
4
+ import random
5
+ from datetime import datetime
6
+ from pathlib import Path
7
+
8
+ # Load templates from JSON
9
+ TEMPLATES_PATH = Path("templates.json")
10
+ if TEMPLATES_PATH.exists():
11
+ with open(TEMPLATES_PATH, "r", encoding="utf-8") as f:
12
+ TEMPLATES = json.load(f)
13
+ else:
14
+ # fallback minimal templates
15
+ TEMPLATES = {
16
+ "text": [
17
+ "{goal}\nAudience: {audience}\nTone: {tone}\nLength: {length}\nConstraints: {constraints}\n\nWrite a clear, structured output with headings and examples."
18
+ ],
19
+ "image": [
20
+ "Scene: {goal}. Style: {tone}. Camera: 35mm; Lighting: golden hour; Colors: warm. Details: {constraints}. Negative: avoid text, watermarks."
21
+ ],
22
+ "code": [
23
+ "Write code to {goal}. Language: {language}. Requirements: {constraints}. Include comments and tests."
24
+ ]
25
+ }
26
+
27
+ def normalize_field(v, default=""):
28
+ if v is None:
29
+ return default
30
+ v = str(v).strip()
31
+ return v if v else default
32
+
33
+ def augment_prompt(prompt, idx):
34
+ extras = [
35
+ "\nInclude examples and a short checklist at the end.",
36
+ "\nUse bullet points for key items and a short summary.",
37
+ "\nProvide 3 alternative phrasings for the main headline.",
38
+ "\nAdd a short FAQ section with 3 questions.",
39
+ "\nInclude a short call-to-action at the end."
40
+ ]
41
+ if idx < len(extras):
42
+ return prompt + extras[idx]
43
+ return prompt
44
+
45
+ def recommend_notes(kind):
46
+ if kind == "image":
47
+ return "Use with image model; try negative prompts to remove artifacts."
48
+ if kind == "code":
49
+ return "Set temperature low; validate output before production."
50
+ return "Use temperature 0.2-0.5 for factual text; review and refine."
51
+
52
+ def generate_variants(kind, goal, tone, audience, length, constraints, language, n_variants):
53
+ templates = TEMPLATES.get(kind, TEMPLATES.get("text"))
54
+ variants = []
55
+ for i in range(n_variants):
56
+ tpl = templates[i % len(templates)]
57
+ prompt = tpl.format(
58
+ goal=goal,
59
+ tone=tone,
60
+ audience=audience,
61
+ length=length,
62
+ constraints=constraints,
63
+ language=language
64
+ )
65
+ prompt = augment_prompt(prompt, i)
66
+ variants.append({
67
+ "id": f"v{i+1}",
68
+ "prompt": prompt,
69
+ "notes": recommend_notes(kind)
70
+ })
71
+ return variants
72
+
73
+ def generate(goal, kind, tone, audience, length, constraints, language, n_variants):
74
+ goal = normalize_field(goal, "Describe the task clearly.")
75
+ tone = normalize_field(tone, "neutral")
76
+ audience = normalize_field(audience, "general")
77
+ length = normalize_field(length, "medium")
78
+ constraints = normalize_field(constraints, "none")
79
+ language = normalize_field(language, "Indonesian")
80
+ try:
81
+ n_variants = int(n_variants)
82
+ except:
83
+ n_variants = 3
84
+ n_variants = max(1, min(5, n_variants))
85
+
86
+ variants = generate_variants(kind, goal, tone, audience, length, constraints, language, n_variants)
87
+ response = {
88
+ "generated_at": datetime.utcnow().isoformat() + "Z",
89
+ "kind": kind,
90
+ "goal": goal,
91
+ "variants": variants
92
+ }
93
+ return json.dumps(response, ensure_ascii=False, indent=2)
94
+
95
+ # Gradio UI
96
+ with gr.Blocks() as demo:
97
+ gr.Markdown("## Gratis AI Prompt Generator\nTemplate based generator. Hasil berupa JSON yang bisa langsung dipakai ke model lain.")
98
+ with gr.Row():
99
+ with gr.Column(scale=1):
100
+ goal = gr.Textbox(label="Goal Ide singkat", placeholder="Contoh: buat artikel SEO tentang kopi robusta")
101
+ kind = gr.Radio(["text", "image", "code"], value="text", label="Tipe output")
102
+ tone = gr.Textbox(label="Tone Gaya", value="informal")
103
+ audience = gr.Textbox(label="Audience", value="pemula")
104
+ length = gr.Textbox(label="Panjang", value="800-1000 kata")
105
+ constraints = gr.Textbox(label="Constraints Catatan khusus", value="sertakan keyword 'kopi robusta'")
106
+ language = gr.Textbox(label="Bahasa output", value="Indonesian")
107
+ n_variants = gr.Slider(minimum=1, maximum=5, step=1, value=3, label="Jumlah varian")
108
+ btn = gr.Button("Generate")
109
+ with gr.Column(scale=1):
110
+ output = gr.Textbox(label="Hasil JSON", lines=20)
111
+ btn.click(fn=generate, inputs=[goal, kind, tone, audience, length, constraints, language, n_variants], outputs=output)
112
+
113
+ if __name__ == "__main__":
114
+ demo.launch(server_name="0.0.0.0", server_port=7860)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio>=3.0
templates.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "text": [
3
+ "{goal}\nAudience: {audience}\nTone: {tone}\nLength: {length}\nConstraints: {constraints}\n\nWrite a clear, structured article with headings, examples, and a short conclusion.",
4
+ "You are an expert writer. Task: {goal}. Target audience: {audience}. Tone: {tone}. Desired length: {length}. Constraints: {constraints}. Provide step-by-step instructions and a short summary.",
5
+ "Create content for {audience} about: {goal}. Style: {tone}. Keep it within {length}. Include intro, 3 key points, and conclusion. Constraints: {constraints}."
6
+ ],
7
+ "image": [
8
+ "A {tone} scene of {goal}. Camera: 35mm; Lighting: golden hour; Colors: warm; Details: {constraints}. Negative: avoid text and watermarks.",
9
+ "Illustration of {goal} in {tone} style. Composition: close-up; Mood: cinematic; Color palette: {constraints}. Render: high detail, photorealistic.",
10
+ "Concept art: {goal}. Style references: cinematic, high detail; Lighting: dramatic rim light; Avoid: low-res, distorted anatomy."
11
+ ],
12
+ "code": [
13
+ "Write code to {goal}. Language: {language}. Requirements: {constraints}. Include comments, tests, and usage example.",
14
+ "Create a {language} script that {goal}. Keep functions modular; include docstrings and error handling. Constraints: {constraints}.",
15
+ "Produce a code snippet for {goal} in {language}. Provide explanation and complexity analysis. Constraints: {constraints}."
16
+ ]
17
+ }
templates_extra.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 20 Template tambahan untuk text image code
2
+
3
+ Text templates
4
+ 1. {goal} Audience: {audience} Tone: {tone} Length: {length} Constraints: {constraints} Provide a headline, subheadings, and 5 bullet takeaways.
5
+ 2. You are a subject matter expert. Create a how-to guide for {goal} aimed at {audience}. Tone: {tone}. Include step-by-step and common mistakes.
6
+ 3. Write an FAQ about {goal} for {audience}. Tone: {tone}. Include at least 8 Q&A pairs and a short summary.
7
+ 4. Produce a listicle titled '7 Tips for {goal}' for {audience}. Tone: {tone}. Each tip must include an example.
8
+ 5. Create a persuasive landing page copy for {goal}. Audience: {audience}. Tone: {tone}. Include CTA and social proof placeholders.
9
+
10
+ Image templates
11
+ 6. Photorealistic shot of {goal} in {tone} style; camera: 50mm; lighting: soft morning; color: muted; avoid text.
12
+ 7. Cinematic wide shot of {goal}; mood: dramatic; palette: cool tones; include environmental details; negative: low detail.
13
+ 8. Minimalist vector illustration of {goal}; colors: flat palette; composition: centered; avoid gradients.
14
+ 9. Fantasy concept art of {goal}; style: high detail; lighting: volumetric; include character and background elements.
15
+ 10. Retro poster of {goal}; style: 70s; colors: warm; typography placeholder; avoid modern elements.
16
+
17
+ Code templates
18
+ 11. Build a CLI tool that {goal} in {language}. Include argument parsing, help text, and examples.
19
+ 12. Create a REST API endpoint that performs {goal}. Language: {language}. Include input validation and tests.
20
+ 13. Write unit tests for a function that {goal}. Language: {language}. Use a common testing framework.
21
+ 14. Implement a data pipeline that ingests data to accomplish {goal}. Include error handling and logging.
22
+ 15. Create a small web app that demonstrates {goal}. Language: {language}. Include README usage.
23
+
24
+ Mixed templates
25
+ 16. Produce an email sequence (3 emails) to promote {goal} to {audience}. Tone: {tone}. Include subject lines and CTAs.
26
+ 17. Create social media posts (5 variations) about {goal}. Platform: Twitter/Instagram. Tone: {tone}. Include hashtags.
27
+ 18. Generate a lesson plan to teach {goal} to {audience}. Include objectives, activities, and assessment.
28
+ 19. Produce a product description and short ad copy for {goal}. Tone: {tone}. Include features and benefits.
29
+ 20. Create a troubleshooting guide for common issues related to {goal}. Audience: {audience}. Tone: {tone}.