openfree commited on
Commit
1156eb8
ยท
verified ยท
1 Parent(s): affbe94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -13
app.py CHANGED
@@ -126,8 +126,14 @@ def initialize_flux_api():
126
  global FLUX_API_ENABLED, flux_api_client
127
 
128
  try:
129
- logger.info("Connecting to FLUX API...")
130
  flux_api_client = Client(FLUX_API_URL)
 
 
 
 
 
 
131
  FLUX_API_ENABLED = True
132
  logger.info("FLUX API connected successfully")
133
  return True
@@ -667,8 +673,7 @@ def generate_flux_prompt(title: str, content: str, style_key: str) -> str:
667
  """
668
  Build a FLUX image-generation prompt for one slide, using six pre-defined
669
  visual styles (Product Design, Mindmap, Mockup, Infographic, Diagram,
670
- Flowchart). `content` is the raw bullet-point block; โ€˜+โ€™/โ€˜-โ€™/โ€˜โ€ขโ€™/โ€˜โ—โ€™ ๋“ฑ
671
- ๋ชจ๋“  ๊ธ€๋จธ๋ฆฌ ๊ธฐํ˜ธ๋ฅผ ์ฒ˜๋ฆฌํ•œ๋‹ค.
672
  """
673
  # 1) clean bullet points (max 8)
674
  bullets = [
@@ -678,28 +683,33 @@ def generate_flux_prompt(title: str, content: str, style_key: str) -> str:
678
  ][:8]
679
 
680
  if bullets:
681
- nodes_block = '\n'.join(f"- {b}" for b in bullets)
682
  tree_block = '\n'.join(
683
  f"{'โ”œโ”€โ”€' if i < len(bullets)-1 else 'โ””โ”€โ”€'} {b}"
684
  for i, b in enumerate(bullets)
685
  )
686
  else:
687
- nodes_block = "- (no explicit bullet points) -"
688
- tree_block = nodes_block
689
 
690
- # 2) choose template & inject nodes
691
  template = EXAMPLE_PROMPTS.get(style_key, EXAMPLE_PROMPTS["Diagram"])
692
- prompt_body = template.format(nodes=nodes_block, tree=tree_block)
693
 
694
- # 3) stylistic tail (โ‰ค120 words total)
695
  tail = (
696
  "corporate colour palette, white background, hand-drawn line style; "
697
  "boxes, arrows, connectors clearly visible; high-resolution vector."
698
  )
699
 
700
- return f"{prompt_body}\n\n{tail}".strip()
701
-
 
 
 
 
 
702
 
 
703
 
704
  def _save_temp_image(img_bytes: bytes, suffix=".png") -> str:
705
  tmp = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
@@ -2260,7 +2270,9 @@ def generate_ppt_content(topic: str, num_slides: int, additional_context: str, u
2260
  5. ๊ฐ ์„น์…˜ ์‚ฌ์ด์— ๋นˆ ์ค„ ์—†์Œ
2261
  6. ์ด {num_slides}์žฅ ์ž‘์„ฑ
2262
  7. ๊ฐ ํฌ์ธํŠธ๋Š” '-' ๊ธฐํ˜ธ๋กœ ์‹œ์ž‘ํ•˜์„ธ์š” (์ด๋ชจ์ง€๋Š” ์ž๋™์œผ๋กœ ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค)
2263
- 8. ๋…ธํŠธ๋Š” ํ•ด๋‹น ์Šฌ๋ผ์ด๋“œ์˜ ๋‚ด์šฉ์„ ๋ฐœํ‘œ์ž๊ฐ€ ์ฒญ์ค‘์—๊ฒŒ ์„ค๋ช…ํ•˜๋Š” ๊ตฌ์–ด์ฒด ๋Œ€๋ณธ์œผ๋กœ ์ž‘์„ฑํ•˜์„ธ์š”"""
 
 
2264
  else:
2265
  system_prompt = f"""You are a professional PPT presentation expert.
2266
  Create content for exactly {num_slides} slides on the given topic.
@@ -2289,6 +2301,8 @@ Notes: [Speaker script]
2289
 
2290
  (Continue this way until Slide {num_slides})
2291
 
 
 
2292
  **Important instructions:**
2293
  1. Each slide starts with "Slide number"
2294
  2. Title: followed by the actual title (no numbers)
@@ -2297,7 +2311,9 @@ Notes: [Speaker script]
2297
  5. No empty lines between sections
2298
  6. Create exactly {num_slides} slides
2299
  7. Start each point with '-' (emojis will be added automatically)
2300
- 8. Notes should be a speaker script explaining the slide content in conversational style"""
 
 
2301
 
2302
  # Add search results if web search is performed
2303
  if additional_context:
@@ -2361,9 +2377,21 @@ Notes: [Speaker script]
2361
  except json.JSONDecodeError:
2362
  logger.warning(f"JSON parsing failed: {data_str}")
2363
  continue
 
 
 
 
2364
 
 
 
 
 
 
 
2365
  except Exception as e:
2366
  logger.error(f"LLM API error: {str(e)}")
 
 
2367
  yield f"โš ๏ธ Error generating content: {str(e)}"
2368
 
2369
  ##############################################################################
 
126
  global FLUX_API_ENABLED, flux_api_client
127
 
128
  try:
129
+ logger.info(f"Connecting to FLUX API at {FLUX_API_URL}...")
130
  flux_api_client = Client(FLUX_API_URL)
131
+
132
+ # API ์ •๋ณด ํ™•์ธ
133
+ if hasattr(flux_api_client, 'view_api'):
134
+ api_info = flux_api_client.view_api()
135
+ logger.info(f"FLUX API endpoints: {api_info}")
136
+
137
  FLUX_API_ENABLED = True
138
  logger.info("FLUX API connected successfully")
139
  return True
 
673
  """
674
  Build a FLUX image-generation prompt for one slide, using six pre-defined
675
  visual styles (Product Design, Mindmap, Mockup, Infographic, Diagram,
676
+ Flowchart).
 
677
  """
678
  # 1) clean bullet points (max 8)
679
  bullets = [
 
683
  ][:8]
684
 
685
  if bullets:
 
686
  tree_block = '\n'.join(
687
  f"{'โ”œโ”€โ”€' if i < len(bullets)-1 else 'โ””โ”€โ”€'} {b}"
688
  for i, b in enumerate(bullets)
689
  )
690
  else:
691
+ # ๋ถˆ๋ฆฟ์ด ์—†์œผ๋ฉด ์ œ๋ชฉ์„ ์‚ฌ์šฉ
692
+ tree_block = f"โ””โ”€โ”€ {title}"
693
 
694
+ # 2) choose template & inject tree only (not nodes)
695
  template = EXAMPLE_PROMPTS.get(style_key, EXAMPLE_PROMPTS["Diagram"])
696
+ prompt_body = template.format(tree=tree_block) # โ† nodes ์ œ๊ฑฐ, tree๋งŒ ์‚ฌ์šฉ
697
 
698
+ # 3) stylistic tail
699
  tail = (
700
  "corporate colour palette, white background, hand-drawn line style; "
701
  "boxes, arrows, connectors clearly visible; high-resolution vector."
702
  )
703
 
704
+ final_prompt = f"{prompt_body}\n\n{tail}".strip()
705
+
706
+ # ๋””๋ฒ„๊น…์šฉ ๋กœ๊ทธ ์ถ”๊ฐ€
707
+ logger.info(f"[FLUX Prompt] Style: {style_key}")
708
+ logger.info(f"[FLUX Prompt] Generated: {final_prompt[:200]}...")
709
+
710
+ return final_prompt
711
 
712
+
713
 
714
  def _save_temp_image(img_bytes: bytes, suffix=".png") -> str:
715
  tmp = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
 
2270
  5. ๊ฐ ์„น์…˜ ์‚ฌ์ด์— ๋นˆ ์ค„ ์—†์Œ
2271
  6. ์ด {num_slides}์žฅ ์ž‘์„ฑ
2272
  7. ๊ฐ ํฌ์ธํŠธ๋Š” '-' ๊ธฐํ˜ธ๋กœ ์‹œ์ž‘ํ•˜์„ธ์š” (์ด๋ชจ์ง€๋Š” ์ž๋™์œผ๋กœ ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค)
2273
+ 8. ๋…ธํŠธ๋Š” ํ•ด๋‹น ์Šฌ๋ผ์ด๋“œ์˜ ๋‚ด์šฉ์„ ๋ฐœํ‘œ์ž๊ฐ€ ์ฒญ์ค‘์—๊ฒŒ ์„ค๋ช…ํ•˜๋Š” ๊ตฌ์–ด์ฒด ๋Œ€๋ณธ์œผ๋กœ ์ž‘์„ฑํ•˜์„ธ์š”
2274
+ 9. ๊ฐ ๊ธ€๋จธ๋ฆฌ ๊ธฐํ˜ธ ํฌ์ธํŠธ๋Š” ๊ตฌ์ฒด์ ์ด๊ณ  ๋ช…ํ™•ํ•˜๊ฒŒ ์ž‘์„ฑํ•˜์„ธ์š”
2275
+ 10. ๋‹ค์ด์–ด๊ทธ๋žจ์ด๋‚˜ ํ”Œ๋กœ์šฐ์ฐจํŠธ๋กœ ํ‘œํ˜„ํ•˜๊ธฐ ์ข‹์€ ๋‚ด์šฉ์€ ๊ตฌ์กฐํ™”๋œ ๋ฐฉ์‹์œผ๋กœ ์ž‘์„ฑํ•˜์„ธ์š”"""
2276
  else:
2277
  system_prompt = f"""You are a professional PPT presentation expert.
2278
  Create content for exactly {num_slides} slides on the given topic.
 
2301
 
2302
  (Continue this way until Slide {num_slides})
2303
 
2304
+ {layout_instructions}
2305
+
2306
  **Important instructions:**
2307
  1. Each slide starts with "Slide number"
2308
  2. Title: followed by the actual title (no numbers)
 
2311
  5. No empty lines between sections
2312
  6. Create exactly {num_slides} slides
2313
  7. Start each point with '-' (emojis will be added automatically)
2314
+ 8. Notes should be a speaker script explaining the slide content in conversational style
2315
+ 9. Make each bullet point specific and clear
2316
+ 10. Structure content that would work well as diagrams or flowcharts"""
2317
 
2318
  # Add search results if web search is performed
2319
  if additional_context:
 
2377
  except json.JSONDecodeError:
2378
  logger.warning(f"JSON parsing failed: {data_str}")
2379
  continue
2380
+
2381
+ # ์ตœ์ข… ์‘๋‹ต ๋กœ๊น… (๋””๋ฒ„๊น…์šฉ)
2382
+ logger.info(f"Generated {len(full_response)} characters of content")
2383
+ logger.debug(f"First 500 chars of response: {full_response[:500]}")
2384
 
2385
+ except requests.exceptions.Timeout:
2386
+ logger.error("LLM API timeout")
2387
+ yield "โš ๏ธ Error: Request timed out. Please try again."
2388
+ except requests.exceptions.RequestException as e:
2389
+ logger.error(f"LLM API request error: {str(e)}")
2390
+ yield f"โš ๏ธ Error: Network error - {str(e)}"
2391
  except Exception as e:
2392
  logger.error(f"LLM API error: {str(e)}")
2393
+ import traceback
2394
+ logger.error(f"Traceback: {traceback.format_exc()}")
2395
  yield f"โš ๏ธ Error generating content: {str(e)}"
2396
 
2397
  ##############################################################################