Update app.py
Browse files
app.py
CHANGED
@@ -594,6 +594,25 @@ def process_uploaded_files(files):
|
|
594 |
return result
|
595 |
|
596 |
# ββββββββββββββββββββββββββββββββ Image & Utility βββββββββββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
597 |
def generate_image(prompt, w=768, h=768, g=3.5, steps=30, seed=3):
|
598 |
"""Image generation function (via Gradio endpoint)."""
|
599 |
if not prompt:
|
@@ -815,7 +834,8 @@ def perplexity_app():
|
|
815 |
img_url = img_data.get('url', '')
|
816 |
caption = img_data.get('title', 'Related image')
|
817 |
if img_url:
|
818 |
-
|
|
|
819 |
if img_data.get('source'):
|
820 |
st.markdown(f"[Source]({img_data['source']})")
|
821 |
except Exception as img_err:
|
@@ -834,7 +854,8 @@ def perplexity_app():
|
|
834 |
col1, col2 = st.columns([1, 3])
|
835 |
with col1:
|
836 |
try:
|
837 |
-
|
|
|
838 |
except:
|
839 |
st.write("π¬")
|
840 |
with col2:
|
@@ -908,7 +929,6 @@ def process_input(query: str, uploaded_files):
|
|
908 |
file_content = process_uploaded_files(uploaded_files)
|
909 |
|
910 |
# μ΅μ’
μ μΌλ‘ μ¬μ©ν μ΄λ―Έμ§/λΉλμ€ λͺ©λ‘ ꡬμ±
|
911 |
-
# (μ΄λ²μλ "fallback" μμ΄ Brave κ²μ κ²°κ³Όλ§ μ¬μ©)
|
912 |
valid_images = []
|
913 |
for img in image_results:
|
914 |
url = img.get('image_url')
|
@@ -991,7 +1011,7 @@ def process_input(query: str, uploaded_files):
|
|
991 |
# μ΅μ’
μλ΅ νμ
|
992 |
message_placeholder.markdown(full_response, unsafe_allow_html=True)
|
993 |
|
994 |
-
# μ€μ κ²μλ μ΄λ―Έμ§λ₯Ό UIμ νμ
|
995 |
if valid_images:
|
996 |
st.subheader("Related Images")
|
997 |
image_cols = st.columns(min(3, len(valid_images)))
|
@@ -1002,13 +1022,13 @@ def process_input(query: str, uploaded_files):
|
|
1002 |
with image_cols[col_idx]:
|
1003 |
img_url = img_data['url']
|
1004 |
caption = img_data['title']
|
1005 |
-
|
1006 |
if img_data.get('source'):
|
1007 |
st.markdown(f"[Source]({img_data['source']})")
|
1008 |
except Exception as img_err:
|
1009 |
logging.warning(f"Error displaying image: {img_err}")
|
1010 |
|
1011 |
-
# μ€μ κ²μλ λΉλμ€λ₯Ό UIμ νμ
|
1012 |
if valid_videos:
|
1013 |
st.subheader("Related Videos")
|
1014 |
for video in valid_videos:
|
@@ -1021,7 +1041,7 @@ def process_input(query: str, uploaded_files):
|
|
1021 |
col1, col2 = st.columns([1, 3])
|
1022 |
with col1:
|
1023 |
try:
|
1024 |
-
|
1025 |
except:
|
1026 |
st.write("π¬")
|
1027 |
with col2:
|
|
|
594 |
return result
|
595 |
|
596 |
# ββββββββββββββββββββββββββββββββ Image & Utility βββββββββββββββββββββββββ
|
597 |
+
|
598 |
+
def load_and_show_image(img_url: str, caption: str = "Image"):
|
599 |
+
"""
|
600 |
+
μ΄λ―Έμ§ URLμ΄ κΉ¨μ Έμκ±°λ μ§μ νμκ° μ λλ κ²½μ°λ₯Ό λλΉν΄
|
601 |
+
requestsλ‘ λ€μ΄λ‘λ ν νμνλ ν¨μ.
|
602 |
+
"""
|
603 |
+
try:
|
604 |
+
# μ΄λ―Έμ§ λ€μ΄λ‘λ
|
605 |
+
response = requests.get(img_url, timeout=10)
|
606 |
+
response.raise_for_status()
|
607 |
+
|
608 |
+
# λ©λͺ¨λ¦¬μμ μ΄λ―Έμ§ μ΄κΈ°
|
609 |
+
image = Image.open(BytesIO(response.content))
|
610 |
+
|
611 |
+
# StreamlitμΌλ‘ νμ
|
612 |
+
st.image(image, caption=caption, use_column_width=True)
|
613 |
+
except Exception as e:
|
614 |
+
st.warning(f"μ΄λ―Έμ§ λ‘λ© μ€ν¨: {e}")
|
615 |
+
|
616 |
def generate_image(prompt, w=768, h=768, g=3.5, steps=30, seed=3):
|
617 |
"""Image generation function (via Gradio endpoint)."""
|
618 |
if not prompt:
|
|
|
834 |
img_url = img_data.get('url', '')
|
835 |
caption = img_data.get('title', 'Related image')
|
836 |
if img_url:
|
837 |
+
# βΆ μ¬κΈ°μ load_and_show_image ν¨μλ₯Ό μ¬μ©νμ¬ λ€μ΄λ‘λ ν νμ
|
838 |
+
load_and_show_image(img_url, caption=caption)
|
839 |
if img_data.get('source'):
|
840 |
st.markdown(f"[Source]({img_data['source']})")
|
841 |
except Exception as img_err:
|
|
|
854 |
col1, col2 = st.columns([1, 3])
|
855 |
with col1:
|
856 |
try:
|
857 |
+
# μΈλ€μΌλ λ€μ΄λ‘λ ν νμ
|
858 |
+
load_and_show_image(thumbnail, caption="Video Thumbnail")
|
859 |
except:
|
860 |
st.write("π¬")
|
861 |
with col2:
|
|
|
929 |
file_content = process_uploaded_files(uploaded_files)
|
930 |
|
931 |
# μ΅μ’
μ μΌλ‘ μ¬μ©ν μ΄λ―Έμ§/λΉλμ€ λͺ©λ‘ ꡬμ±
|
|
|
932 |
valid_images = []
|
933 |
for img in image_results:
|
934 |
url = img.get('image_url')
|
|
|
1011 |
# μ΅μ’
μλ΅ νμ
|
1012 |
message_placeholder.markdown(full_response, unsafe_allow_html=True)
|
1013 |
|
1014 |
+
# μ€μ κ²μλ μ΄λ―Έμ§λ₯Ό UIμ νμ (load_and_show_image μ¬μ©)
|
1015 |
if valid_images:
|
1016 |
st.subheader("Related Images")
|
1017 |
image_cols = st.columns(min(3, len(valid_images)))
|
|
|
1022 |
with image_cols[col_idx]:
|
1023 |
img_url = img_data['url']
|
1024 |
caption = img_data['title']
|
1025 |
+
load_and_show_image(img_url, caption=caption)
|
1026 |
if img_data.get('source'):
|
1027 |
st.markdown(f"[Source]({img_data['source']})")
|
1028 |
except Exception as img_err:
|
1029 |
logging.warning(f"Error displaying image: {img_err}")
|
1030 |
|
1031 |
+
# μ€μ κ²μλ λΉλμ€λ₯Ό UIμ νμ (load_and_show_imageλ‘ μΈλ€μΌ μ²λ¦¬)
|
1032 |
if valid_videos:
|
1033 |
st.subheader("Related Videos")
|
1034 |
for video in valid_videos:
|
|
|
1041 |
col1, col2 = st.columns([1, 3])
|
1042 |
with col1:
|
1043 |
try:
|
1044 |
+
load_and_show_image(thumbnail, caption="Video Thumbnail")
|
1045 |
except:
|
1046 |
st.write("π¬")
|
1047 |
with col2:
|