Akhmad123 commited on
Commit
a29280e
·
verified ·
1 Parent(s): 083c348

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -42,17 +42,22 @@ def ensure_outputs_dir():
42
  os.makedirs("outputs", exist_ok=True)
43
 
44
  # ============================
45
- # AI TEXT GENERATOR (LLaMA‑3)
46
  # ============================
47
  def ai_generate(prompt):
48
  try:
49
  output = replicate.run(
50
  "meta/meta-llama-3-8b-instruct",
51
- input={"prompt": prompt, "max_tokens": 500}
 
 
 
 
 
52
  )
53
  return "".join(output)
54
- except:
55
- return "AI gagal menghasilkan teks."
56
 
57
  def generate_chapter_text(goal, style, tone, chapter_title):
58
  prompt = f"""
@@ -67,7 +72,7 @@ def generate_chapter_text(goal, style, tone, chapter_title):
67
  return ai_generate(prompt)
68
 
69
  # ============================
70
- # REPLICATE (FREE MODELS)
71
  # ============================
72
  def generate_image_flux(prompt):
73
  try:
@@ -170,7 +175,7 @@ def build_ebook_pdf_with_images(username, goal, genre, tone, style, length,
170
  for i, ch in enumerate(chapters, start=1):
171
  pdf.cell(0, 8, safe_text(f"{i}. {ch}"), 0, 1)
172
 
173
- # CHAPTERS (LANGSUNG BAB 1–N, TANPA RINGKASAN/OUTLINE)
174
  for idx, ch in enumerate(chapters, start=1):
175
  pdf.add_page()
176
  pdf.set_font("Helvetica", "B", 16)
 
42
  os.makedirs("outputs", exist_ok=True)
43
 
44
  # ============================
45
+ # AI TEXT GENERATOR (LLaMA‑3 FIXED)
46
  # ============================
47
  def ai_generate(prompt):
48
  try:
49
  output = replicate.run(
50
  "meta/meta-llama-3-8b-instruct",
51
+ input={
52
+ "messages": [
53
+ {"role": "user", "content": prompt}
54
+ ],
55
+ "max_tokens": 500
56
+ }
57
  )
58
  return "".join(output)
59
+ except Exception as e:
60
+ return f"AI gagal menghasilkan teks. Error: {str(e)}"
61
 
62
  def generate_chapter_text(goal, style, tone, chapter_title):
63
  prompt = f"""
 
72
  return ai_generate(prompt)
73
 
74
  # ============================
75
+ # REPLICATE IMAGE MODELS
76
  # ============================
77
  def generate_image_flux(prompt):
78
  try:
 
175
  for i, ch in enumerate(chapters, start=1):
176
  pdf.cell(0, 8, safe_text(f"{i}. {ch}"), 0, 1)
177
 
178
+ # CHAPTERS (AI TEXT)
179
  for idx, ch in enumerate(chapters, start=1):
180
  pdf.add_page()
181
  pdf.set_font("Helvetica", "B", 16)