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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -6,6 +6,7 @@ import os
6
  import uuid
7
  import requests
8
  import replicate
 
9
 
10
  # ============================
11
  # CONFIG
@@ -13,6 +14,10 @@ import replicate
13
  REPLICATE_API_TOKEN = "r8_OHfjZvEbVoU9fuioi4qfQ50OHdpAmqV4OAa5b"
14
  os.environ["REPLICATE_API_TOKEN"] = REPLICATE_API_TOKEN
15
 
 
 
 
 
16
  MAX_CHAPTERS = 10
17
 
18
  # ============================
@@ -42,20 +47,16 @@ def ensure_outputs_dir():
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
 
@@ -195,7 +196,7 @@ def build_ebook_pdf_with_images(username, goal, genre, tone, style, length,
195
  pdf.image(illus_path, x=20, y=y_start, w=170)
196
  pdf.set_y(y_start + 80)
197
 
198
- # AI CHAPTER TEXT
199
  chapter_text = generate_chapter_text(goal, style, tone, ch)
200
 
201
  pdf.set_font("Helvetica", "", 12)
@@ -271,7 +272,7 @@ with gr.Blocks() as demo:
271
 
272
  with gr.Group(visible=False) as main_ui:
273
 
274
- gr.Markdown("# 🌟 AIPromptLab — JSON & PDF E-Book Generator (Replicate FREE Models)")
275
 
276
  with gr.Tabs():
277
 
 
6
  import uuid
7
  import requests
8
  import replicate
9
+ from groq import Groq
10
 
11
  # ============================
12
  # CONFIG
 
14
  REPLICATE_API_TOKEN = "r8_OHfjZvEbVoU9fuioi4qfQ50OHdpAmqV4OAa5b"
15
  os.environ["REPLICATE_API_TOKEN"] = REPLICATE_API_TOKEN
16
 
17
+ # === MASUKKAN API KEY GROQ DI SINI ===
18
+ GROQ_API_KEY = "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"
19
+ client = Groq(api_key=GROQ_API_KEY)
20
+
21
  MAX_CHAPTERS = 10
22
 
23
  # ============================
 
47
  os.makedirs("outputs", exist_ok=True)
48
 
49
  # ============================
50
+ # AI TEXT GENERATOR (GROQ LLaMA‑3 70B)
51
  # ============================
52
  def ai_generate(prompt):
53
  try:
54
+ response = client.chat.completions.create(
55
+ model="llama3-70b-8192",
56
+ messages=[{"role": "user", "content": prompt}],
57
+ max_tokens=600
 
 
 
 
58
  )
59
+ return response.choices[0].message.content
60
  except Exception as e:
61
  return f"AI gagal menghasilkan teks. Error: {str(e)}"
62
 
 
196
  pdf.image(illus_path, x=20, y=y_start, w=170)
197
  pdf.set_y(y_start + 80)
198
 
199
+ # AI CHAPTER TEXT (GROQ)
200
  chapter_text = generate_chapter_text(goal, style, tone, ch)
201
 
202
  pdf.set_font("Helvetica", "", 12)
 
272
 
273
  with gr.Group(visible=False) as main_ui:
274
 
275
+ gr.Markdown("# 🌟 AIPromptLab — JSON & PDF E-Book Generator (Groq + Replicate)")
276
 
277
  with gr.Tabs():
278