parkkyujin commited on
Commit
193d7cb
ยท
verified ยท
1 Parent(s): 5c49b7e

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +10 -19
streamlit_app.py CHANGED
@@ -66,26 +66,17 @@ st.markdown("---")
66
  # ์‚ฌ์ด๋“œ๋ฐ” ์„ค์ •
67
  st.sidebar.header("๐ŸŽ›๏ธ ์นดํ”ผ ์ƒ์„ฑ ์„ค์ •")
68
 
 
 
 
69
 
70
- # 1. ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ API ํ‚ค๋ฅผ ๋จผ์ € ๊ฐ€์ ธ์˜ค๋ ค๊ณ  ์‹œ๋„
71
- default_api_key = os.getenv("GEMINI_API_KEY", "")
72
-
73
- # 2. st.sidebar.text_input์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ API ํ‚ค๋ฅผ ์ž…๋ ฅ๋ฐ›๊ฑฐ๋‚˜,
74
- # ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๊ฐ€์ ธ์˜จ ๊ฐ’์„ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ๋ณด์—ฌ์คŒ
75
- api_key_value = st.sidebar.text_input(
76
- "๐Ÿ”‘ Gemini API ํ‚ค",
77
- value=default_api_key,
78
- type="password",
79
- help="ํ™˜๊ฒฝ๋ณ€์ˆ˜์— GEMINI_API_KEY๋กœ ์„ค์ •ํ•˜๋ฉด ์ž๋™ ์ž…๋ ฅ๋ฉ๋‹ˆ๋‹ค",
80
- key="gemini_api_key_input"
81
- )
82
-
83
- # 3. ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ๊ฐ€์ ธ์˜จ API ํ‚ค ๊ฐ’์„ ์‚ฌ์šฉ
84
  if not api_key_value:
85
- st.warning("โš ๏ธ Gemini API ํ‚ค๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
86
- st.info("๐Ÿ’ก Settings โ†’ Repository secrets์—์„œ GEMINI_API_KEY๋ฅผ ์„ค์ •ํ•˜์„ธ์š”")
 
87
  st.stop()
88
-
89
 
90
  # ์‹œ์Šคํ…œ ์ดˆ๊ธฐํ™” (์บ์‹ฑ) - ์ž„๋ฒ ๋”ฉ ํ•„์ˆ˜!
91
  @st.cache_resource(show_spinner=False)
@@ -337,7 +328,7 @@ def generate_copy_with_rag(user_req, category_filter, target_aud, brand_tn, crea
337
  similarities = cosine_similarity(query_embedding, filtered_embeddings_for_search)[0]
338
  num_to_select = min(num_references, len(similarities))
339
  # numpy๋ฅผ ์—ฌ๊ธฐ์„œ ๋‹ค์‹œ ์ž„ํฌํŠธํ•˜์—ฌ ์‚ฌ์šฉ (np ๋ณ„์นญ ์‚ฌ์šฉ)
340
- import numpy as np_generate_rag
341
  top_similarity_indices = np_generate_rag.argsort(similarities)[::-1][:num_to_select]
342
 
343
  reference_copies = []
@@ -490,4 +481,4 @@ if os.getenv("DEBUG_MODE") == "true":
490
  st.sidebar.write("Numpy ๋ฒ„์ „ (Global): Not imported or error")
491
 
492
  # torch๋Š” ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ, sentence_transformers ๋‚ด๋ถ€ ๋ฒ„์ „์„ ์•Œ๊ธฐ๋Š” ์–ด๋ ค์›€
493
- st.sidebar.write(f"google-generativeai ๋ฒ„์ „: {genai.__version__}")
 
66
  # ์‚ฌ์ด๋“œ๋ฐ” ์„ค์ •
67
  st.sidebar.header("๐ŸŽ›๏ธ ์นดํ”ผ ์ƒ์„ฑ ์„ค์ •")
68
 
69
+ # --- API ํ‚ค ์ฒ˜๋ฆฌ ๋ณ€๊ฒฝ ---
70
+ # ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ API ํ‚ค๋ฅผ ์ง์ ‘ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
71
+ api_key_value = os.getenv("GEMINI_API_KEY")
72
 
73
+ # API ํ‚ค๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์•ฑ ์ค‘๋‹จ ๋ฐ ์•ˆ๋‚ด ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  if not api_key_value:
75
+ st.error(" critical: ๐Ÿ”‘ GEMINI_API_KEY ํ™˜๊ฒฝ ๋ณ€์ˆ˜๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.")
76
+ st.info("Hugging Face Spaces์˜ 'Settings' -> 'Repository secrets'์—์„œ 'GEMINI_API_KEY'๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.")
77
+ st.info("์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ž‘๋™ํ•˜๋ ค๋ฉด API ํ‚ค๊ฐ€ ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
78
  st.stop()
79
+ # --- API ํ‚ค ์ฒ˜๋ฆฌ ๋ณ€๊ฒฝ ๋ ---
80
 
81
  # ์‹œ์Šคํ…œ ์ดˆ๊ธฐํ™” (์บ์‹ฑ) - ์ž„๋ฒ ๋”ฉ ํ•„์ˆ˜!
82
  @st.cache_resource(show_spinner=False)
 
328
  similarities = cosine_similarity(query_embedding, filtered_embeddings_for_search)[0]
329
  num_to_select = min(num_references, len(similarities))
330
  # numpy๋ฅผ ์—ฌ๊ธฐ์„œ ๋‹ค์‹œ ์ž„ํฌํŠธํ•˜์—ฌ ์‚ฌ์šฉ (np ๋ณ„์นญ ์‚ฌ์šฉ)
331
+ import numpy as np_generate_rag
332
  top_similarity_indices = np_generate_rag.argsort(similarities)[::-1][:num_to_select]
333
 
334
  reference_copies = []
 
481
  st.sidebar.write("Numpy ๋ฒ„์ „ (Global): Not imported or error")
482
 
483
  # torch๋Š” ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ, sentence_transformers ๋‚ด๋ถ€ ๋ฒ„์ „์„ ์•Œ๊ธฐ๋Š” ์–ด๋ ค์›€
484
+ st.sidebar.write(f"google-generativeai ๋ฒ„์ „: {genai.__version__}")