seawolf2357 commited on
Commit
d31a076
ยท
verified ยท
1 Parent(s): 4ed4d6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -36
app.py CHANGED
@@ -398,36 +398,40 @@ def update_session_list():
398
  return gr.update(choices=[])
399
 
400
  def load_json_data():
401
- try:
402
- current_dir = os.path.dirname(os.path.abspath(__file__))
403
- json_path = os.path.join(current_dir, 'db.json')
404
- print(f"Attempting to load JSON from: {json_path}")
405
-
406
- with open(json_path, 'r', encoding='utf-8') as f:
407
- data = json.load(f)
408
- print(f"Successfully loaded {len(data)} items from db.json")
409
- return data
410
- except Exception as e:
411
- print(f"Error loading db.json: {str(e)}")
412
- # ์—๋Ÿฌ ์‹œ ๊ธฐ๋ณธ ๋ฐ์ดํ„ฐ ๋ฐ˜ํ™˜
413
- return [
414
- {
415
- "name": "MBTI ์ง„๋‹จ ์„œ๋น„์Šค",
416
- "image_url": "mbti.png",
417
- "prompt": "MBTI ์ง„๋‹จ์„ ์œ„ํ•ด 15๊ฐœ์˜ ์งˆ๋ฌธ๊ณผ ๊ฐ๊ด€์‹ ๋‹ต๋ณ€์„ ํ†ตํ•ด MBTI ์ง„๋‹จ ๊ฒฐ๊ณผ ๋ฐ ํ•ด๋‹น ์„ฑ๊ฒฉ์— ๋Œ€ํ•œ ์ƒ์„ธํ•œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋ผ"
418
- },
419
- {
420
- "name": "ํˆฌ์ž ํฌํŠธํด๋ฆฌ์˜ค ๋Œ€์‹œ๋ณด๋“œ",
421
- "image_url": "chart.png",
422
- "prompt": "Create an interactive dashboard with Chart.js showing different types of charts..."
423
- }
424
- ]
 
 
 
 
425
 
426
  def load_session_history(selected_session=None):
427
  try:
428
  print("Loading session history...")
429
  json_data = load_json_data()
430
- print(f"Loaded {len(json_data)} items from JSON")
431
 
432
  html_content = """
433
  <style>
@@ -451,17 +455,12 @@ def load_session_history(selected_session=None):
451
  transform: translateY(-2px);
452
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
453
  }
454
- .card-image-placeholder {
455
  width: 100%;
456
  height: 200px;
457
- background-color: #f5f5f5;
458
- display: flex;
459
- align-items: center;
460
- justify-content: center;
461
  border-radius: 4px;
462
  margin-bottom: 10px;
463
- color: #999;
464
- font-size: 14px;
465
  }
466
  .card-name {
467
  font-weight: bold;
@@ -482,13 +481,12 @@ def load_session_history(selected_session=None):
482
 
483
  for item in json_data:
484
  name = html.escape(item.get('name', ''))
485
- image_path = item.get('image_url', '')
486
  prompt = html.escape(item.get('prompt', ''))
487
 
488
- # ์ด๋ฏธ์ง€ ๋Œ€์‹  ํ”Œ๋ ˆ์ด์Šคํ™€๋” ์‚ฌ์šฉ
489
  html_content += f"""
490
  <div class="prompt-card" data-prompt="{prompt}" onclick="handleCardClick(this)">
491
- <div class="card-image-placeholder">No Image</div>
492
  <div class="card-name">{name}</div>
493
  <div class="card-prompt">{prompt}</div>
494
  </div>
@@ -523,7 +521,6 @@ def load_session_history(selected_session=None):
523
  </script>
524
  """
525
 
526
- print("Generated HTML content length:", len(html_content))
527
  return gr.HTML(value=html_content)
528
 
529
  except Exception as e:
 
398
  return gr.update(choices=[])
399
 
400
  def load_json_data():
401
+ # ํ•˜๋“œ์ฝ”๋”ฉ๋œ ๋ฐ์ดํ„ฐ ๋ฐ˜ํ™˜
402
+ return [
403
+ {
404
+ "name": "MBTI ์ง„๋‹จ ์„œ๋น„์Šค",
405
+ "image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'), # mouse.gif ์‚ฌ์šฉ
406
+ "prompt": "MBTI ์ง„๋‹จ์„ ์œ„ํ•ด 15๊ฐœ์˜ ์งˆ๋ฌธ๊ณผ ๊ฐ๊ด€์‹ ๋‹ต๋ณ€์„ ํ†ตํ•ด MBTI ์ง„๋‹จ ๊ฒฐ๊ณผ ๋ฐ ํ•ด๋‹น ์„ฑ๊ฒฉ์— ๋Œ€ํ•œ ์ƒ์„ธํ•œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋ผ"
407
+ },
408
+ {
409
+ "name": "ํˆฌ์ž ํฌํŠธํด๋ฆฌ์˜ค ๋Œ€์‹œ๋ณด๋“œ",
410
+ "image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'), # mouse.gif ์‚ฌ์šฉ
411
+ "prompt": "Create an interactive dashboard with Chart.js showing different types of charts (line, bar, pie) with smooth animations. Include buttons to switch between different data views.ํˆฌ์ž ํฌํŠธํด๋ฆฌ์˜ค๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์œ„ํ—˜๋„, ์ˆ˜์ต๋ฅ , ์ž์‚ฐ ๋ฐฐ๋ถ„์„ ์‹œ๊ฐํ™”ํ•˜๋Š” ํˆฌ์ž ๊ด€๋ฆฌ ๋„๊ตฌ๋ฅผ ๋งŒ๋“œ์„ธ์š”."
412
+ },
413
+ {
414
+ "name": "์ฒด์Šค ๊ฒŒ์ž„",
415
+ "image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'), # mouse.gif ์‚ฌ์šฉ
416
+ "prompt": "์ฒด์Šค ๊ฒŒ์ž„: ์ฒด์Šค ๊ฒŒ์ž„์˜ ๋ฃฐ์„ ์ •ํ™•ํ•˜๊ฒŒ ์‹๋ณ„ํ•˜๊ณ  ์ ์šฉํ•˜๋ผ, ์ƒ๋Œ€๋ฐฉ์€ auto๋กœ ๊ฒŒ์ž„์„ ์ง„ํ–‰ํ•˜๋ผ"
417
+ },
418
+ {
419
+ "name": "ํƒ€๋กœ์นด๋“œ ์šด์„ธ",
420
+ "image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'), # mouse.gif ์‚ฌ์šฉ
421
+ "prompt": "ํƒ€๋กœ์นด๋“œ ์šด์„ธ๋ฅผ ์ ์น˜๋Š”๊ฒƒ์„ ์ƒ์„ฑํ•˜๋ผ. ์•„์ฃผ ์ƒ์„ธํ•˜๊ณ  ์ „๋ฌธ์ ์ด๋ฉด์„œ ์‰ฝ๊ณ  ๊ธธ๊ฒŒ ๋‹ต๋ณ€ํ•˜๋ผ. ๋ชจ๋“  ๋‹ต๋ณ€๊ณผ ์„ค๋ช…์€ ํ•œ๊ธ€๋กœ ํ•˜๋ผ"
422
+ },
423
+ {
424
+ "name": "๋ฒฝ๋Œ๊นจ๊ธฐ ๊ฒŒ์ž„",
425
+ "image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'), # mouse.gif ์‚ฌ์šฉ
426
+ "prompt": "๋ฒฝ๋Œ๊นจ๊ธฐ ๊ฒŒ์ž„"
427
+ }
428
+ ]
429
 
430
  def load_session_history(selected_session=None):
431
  try:
432
  print("Loading session history...")
433
  json_data = load_json_data()
434
+ print(f"Loaded {len(json_data)} items")
435
 
436
  html_content = """
437
  <style>
 
455
  transform: translateY(-2px);
456
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
457
  }
458
+ .card-image {
459
  width: 100%;
460
  height: 200px;
461
+ object-fit: cover;
 
 
 
462
  border-radius: 4px;
463
  margin-bottom: 10px;
 
 
464
  }
465
  .card-name {
466
  font-weight: bold;
 
481
 
482
  for item in json_data:
483
  name = html.escape(item.get('name', ''))
484
+ image_url = item.get('image_url', '') # ์ด๋ฏธ base64 ์ธ์ฝ”๋”ฉ๋œ ์ด๋ฏธ์ง€ URL
485
  prompt = html.escape(item.get('prompt', ''))
486
 
 
487
  html_content += f"""
488
  <div class="prompt-card" data-prompt="{prompt}" onclick="handleCardClick(this)">
489
+ <img src="{image_url}" class="card-image" alt="{name}">
490
  <div class="card-name">{name}</div>
491
  <div class="card-prompt">{prompt}</div>
492
  </div>
 
521
  </script>
522
  """
523
 
 
524
  return gr.HTML(value=html_content)
525
 
526
  except Exception as e: