Harshdhsvguyt commited on
Commit
19be839
Β·
verified Β·
1 Parent(s): 843709f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -15
app.py CHANGED
@@ -5,12 +5,10 @@ import uuid
5
  from datetime import datetime, timezone
6
  from pathlib import Path
7
  from providers.pollinations_provider import PollinationsProvider
8
-
9
  from providers.hf_provider import HuggingFaceProvider
10
  from providers.stub_provider import StubProvider
11
- from datetime import datetime, timezone
12
-
13
  from dotenv import load_dotenv
 
14
  load_dotenv()
15
 
16
  # ==============================================
@@ -71,7 +69,12 @@ def get_provider(kind, model):
71
  # ==============================================
72
  def save_to_history(asset_type, prompt, negative_prompt, provider, model_name, results, metadata=None):
73
  """Save generation to history"""
74
- history = json.loads(PROMPT_HISTORY.read_text())
 
 
 
 
 
75
  entry = {
76
  "id": uuid.uuid4().hex,
77
  "asset_type": asset_type,
@@ -90,7 +93,11 @@ def save_to_history(asset_type, prompt, negative_prompt, provider, model_name, r
90
 
91
  def add_feedback(entry_id, feedback_text, rating):
92
  """Add feedback to a generation"""
93
- history = json.loads(PROMPT_HISTORY.read_text())
 
 
 
 
94
  for entry in history:
95
  if entry["id"] == entry_id:
96
  entry["feedback"].append({
@@ -256,8 +263,16 @@ with tab1:
256
  if idea_text and len(idea_text) > 10:
257
  st.markdown("### πŸš€ Prompt Enhancer")
258
 
259
- from utils.prompt_enhancer import enhance_prompt
260
- enhanced = enhance_prompt(idea_text)
 
 
 
 
 
 
 
 
261
 
262
  enhanced_choice = st.radio(
263
  "Select Enhanced Version:",
@@ -335,8 +350,15 @@ with tab2:
335
  if prompt and len(prompt) > 10:
336
  st.markdown("### πŸš€ Select Enhanced Prompt (Required)")
337
 
338
- from utils.prompt_enhancer import enhance_prompt
339
- enhanced = enhance_prompt(prompt)
 
 
 
 
 
 
 
340
 
341
  # Show all three options with their full text
342
  st.markdown("**Choose one enhancement:**")
@@ -405,7 +427,8 @@ with tab2:
405
  cols = st.columns(min(len(saved), 3))
406
  for idx, (c, path) in enumerate(zip(cols, saved)):
407
  with c:
408
- c.image(path, use_container_width=True)
 
409
  c.download_button(
410
  "Download",
411
  data=open(path, "rb"),
@@ -476,8 +499,15 @@ with tab3:
476
  if video_prompt and len(video_prompt) > 10:
477
  st.markdown("### πŸš€ Select Enhanced Prompt (Required)")
478
 
479
- from utils.prompt_enhancer import enhance_prompt
480
- enhanced = enhance_prompt(video_prompt)
 
 
 
 
 
 
 
481
 
482
  enhanced_choice = st.radio(
483
  "Choose one enhancement:",
@@ -607,7 +637,8 @@ with tab5:
607
  cols = st.columns(cols_per_row)
608
  for idx, f in enumerate(files[i:i+cols_per_row]):
609
  with cols[idx]:
610
- st.image(str(f), use_container_width=True)
 
611
  st.caption(f.name)
612
  col_dl, col_fb = st.columns(2)
613
  with col_dl:
@@ -626,6 +657,7 @@ with tab5:
626
  for f in files:
627
  col1, col2, col3 = st.columns([3, 1, 1])
628
  with col1:
 
629
  st.image(str(f), width=300)
630
  with col2:
631
  st.write(f"**{f.name}**")
@@ -645,7 +677,10 @@ with tab5:
645
  with tab6:
646
  st.header("πŸ“œ Prompt History & Feedback System")
647
 
648
- history = json.loads(PROMPT_HISTORY.read_text())
 
 
 
649
 
650
  if not history:
651
  st.info("No generation history yet.")
@@ -668,7 +703,8 @@ with tab6:
668
  result_cols = st.columns(min(len(item['results']), 3))
669
  for idx, (col, path) in enumerate(zip(result_cols, item['results'])):
670
  if Path(path).exists():
671
- col.image(path, use_container_width=True)
 
672
 
673
  with col2:
674
  st.markdown("**Feedback & Iteration**")
 
5
  from datetime import datetime, timezone
6
  from pathlib import Path
7
  from providers.pollinations_provider import PollinationsProvider
 
8
  from providers.hf_provider import HuggingFaceProvider
9
  from providers.stub_provider import StubProvider
 
 
10
  from dotenv import load_dotenv
11
+
12
  load_dotenv()
13
 
14
  # ==============================================
 
69
  # ==============================================
70
  def save_to_history(asset_type, prompt, negative_prompt, provider, model_name, results, metadata=None):
71
  """Save generation to history"""
72
+ try:
73
+ history_content = PROMPT_HISTORY.read_text()
74
+ history = json.loads(history_content) if history_content else []
75
+ except json.JSONDecodeError:
76
+ history = []
77
+
78
  entry = {
79
  "id": uuid.uuid4().hex,
80
  "asset_type": asset_type,
 
93
 
94
  def add_feedback(entry_id, feedback_text, rating):
95
  """Add feedback to a generation"""
96
+ try:
97
+ history = json.loads(PROMPT_HISTORY.read_text())
98
+ except json.JSONDecodeError:
99
+ return
100
+
101
  for entry in history:
102
  if entry["id"] == entry_id:
103
  entry["feedback"].append({
 
263
  if idea_text and len(idea_text) > 10:
264
  st.markdown("### πŸš€ Prompt Enhancer")
265
 
266
+ # Helper to simulate enhancer if utils missing
267
+ try:
268
+ from utils.prompt_enhancer import enhance_prompt
269
+ enhanced = enhance_prompt(idea_text)
270
+ except ImportError:
271
+ enhanced = {
272
+ "Cinematic": f"Cinematic shot of {idea_text}, 8k, highly detailed",
273
+ "Photorealistic": f"Photorealistic photo of {idea_text}, canon eos r5, 50mm",
274
+ "Artistic": f"Digital art of {idea_text}, trending on artstation"
275
+ }
276
 
277
  enhanced_choice = st.radio(
278
  "Select Enhanced Version:",
 
350
  if prompt and len(prompt) > 10:
351
  st.markdown("### πŸš€ Select Enhanced Prompt (Required)")
352
 
353
+ try:
354
+ from utils.prompt_enhancer import enhance_prompt
355
+ enhanced = enhance_prompt(prompt)
356
+ except ImportError:
357
+ enhanced = {
358
+ "Cinematic": f"Cinematic shot of {prompt}, 8k, highly detailed",
359
+ "Photorealistic": f"Photorealistic photo of {prompt}, canon eos r5, 50mm",
360
+ "Artistic": f"Digital art of {prompt}, trending on artstation"
361
+ }
362
 
363
  # Show all three options with their full text
364
  st.markdown("**Choose one enhancement:**")
 
427
  cols = st.columns(min(len(saved), 3))
428
  for idx, (c, path) in enumerate(zip(cols, saved)):
429
  with c:
430
+ # FIXED: Changed use_container_width to use_column_width
431
+ c.image(path, use_column_width=True)
432
  c.download_button(
433
  "Download",
434
  data=open(path, "rb"),
 
499
  if video_prompt and len(video_prompt) > 10:
500
  st.markdown("### πŸš€ Select Enhanced Prompt (Required)")
501
 
502
+ try:
503
+ from utils.prompt_enhancer import enhance_prompt
504
+ enhanced = enhance_prompt(video_prompt)
505
+ except ImportError:
506
+ enhanced = {
507
+ "Cinematic Motion": f"{video_prompt}, cinematic camera movement, smooth stabilization",
508
+ "Dynamic Action": f"{video_prompt}, dynamic angle, fast paced",
509
+ "Slow Mo": f"{video_prompt}, slow motion, 60fps, detailed"
510
+ }
511
 
512
  enhanced_choice = st.radio(
513
  "Choose one enhancement:",
 
637
  cols = st.columns(cols_per_row)
638
  for idx, f in enumerate(files[i:i+cols_per_row]):
639
  with cols[idx]:
640
+ # FIXED: Changed use_container_width to use_column_width
641
+ st.image(str(f), use_column_width=True)
642
  st.caption(f.name)
643
  col_dl, col_fb = st.columns(2)
644
  with col_dl:
 
657
  for f in files:
658
  col1, col2, col3 = st.columns([3, 1, 1])
659
  with col1:
660
+ # FIXED: Changed width parameter logic for compatibility
661
  st.image(str(f), width=300)
662
  with col2:
663
  st.write(f"**{f.name}**")
 
677
  with tab6:
678
  st.header("πŸ“œ Prompt History & Feedback System")
679
 
680
+ try:
681
+ history = json.loads(PROMPT_HISTORY.read_text())
682
+ except json.JSONDecodeError:
683
+ history = []
684
 
685
  if not history:
686
  st.info("No generation history yet.")
 
703
  result_cols = st.columns(min(len(item['results']), 3))
704
  for idx, (col, path) in enumerate(zip(result_cols, item['results'])):
705
  if Path(path).exists():
706
+ # FIXED: Changed use_container_width to use_column_width
707
+ col.image(path, use_column_width=True)
708
 
709
  with col2:
710
  st.markdown("**Feedback & Iteration**")