Update src/streamlit_app.py
Browse files- src/streamlit_app.py +6 -4
src/streamlit_app.py
CHANGED
|
@@ -9,6 +9,10 @@ import json
|
|
| 9 |
from langdetect import detect, DetectorFactory
|
| 10 |
from gtts import gTTS
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Initialize Mega client and login securely
|
| 13 |
mega = Mega()
|
| 14 |
MEGA_EMAIL = os.getenv("MEGA_EMAIL")
|
|
@@ -27,7 +31,7 @@ def upload_to_mega(filepath):
|
|
| 27 |
|
| 28 |
def get_font_for_language(lang_code, size=28):
|
| 29 |
try:
|
| 30 |
-
return ImageFont.truetype(
|
| 31 |
except Exception as e:
|
| 32 |
st.warning(f"Could not load font: {e}")
|
| 33 |
return ImageFont.load_default()
|
|
@@ -63,7 +67,6 @@ if submitted and story.strip():
|
|
| 63 |
# Use /tmp directory for saving temp files to avoid permission errors
|
| 64 |
tmp_dir = "/tmp"
|
| 65 |
if not os.path.exists(tmp_dir):
|
| 66 |
-
# For local testing where /tmp might not exist, fallback to current directory
|
| 67 |
tmp_dir = "."
|
| 68 |
|
| 69 |
# Generate unique filenames and paths
|
|
@@ -125,7 +128,6 @@ if submitted and story.strip():
|
|
| 125 |
with open(card_path, "rb") as f:
|
| 126 |
st.download_button("Download Story Card", f, file_name=card_filename)
|
| 127 |
st.image(card_path, caption="Your Story Card", use_container_width=True)
|
| 128 |
-
|
| 129 |
st.success("Story card generated!")
|
| 130 |
except Exception as e:
|
| 131 |
st.error(f"Story card generation failed: {e}")
|
|
@@ -137,7 +139,7 @@ if submitted and story.strip():
|
|
| 137 |
st.success("Files uploaded to MEGA successfully!")
|
| 138 |
st.audio(audio_url)
|
| 139 |
st.markdown(f"[Download Audio]({audio_url})")
|
| 140 |
-
st.image(card_url, caption="Your Story Card")
|
| 141 |
st.markdown(f"[Download Card]({card_url})")
|
| 142 |
except Exception as e:
|
| 143 |
st.error(f"Failed to upload files to MEGA: {e}")
|
|
|
|
| 9 |
from langdetect import detect, DetectorFactory
|
| 10 |
from gtts import gTTS
|
| 11 |
|
| 12 |
+
# Find the directory this script is in
|
| 13 |
+
this_dir = os.path.dirname(os.path.abspath(__file__))
|
| 14 |
+
font_path = os.path.join(this_dir, "NotoSansTelugu-VariableFont_wdth,wght.ttf")
|
| 15 |
+
|
| 16 |
# Initialize Mega client and login securely
|
| 17 |
mega = Mega()
|
| 18 |
MEGA_EMAIL = os.getenv("MEGA_EMAIL")
|
|
|
|
| 31 |
|
| 32 |
def get_font_for_language(lang_code, size=28):
|
| 33 |
try:
|
| 34 |
+
return ImageFont.truetype(font_path, size)
|
| 35 |
except Exception as e:
|
| 36 |
st.warning(f"Could not load font: {e}")
|
| 37 |
return ImageFont.load_default()
|
|
|
|
| 67 |
# Use /tmp directory for saving temp files to avoid permission errors
|
| 68 |
tmp_dir = "/tmp"
|
| 69 |
if not os.path.exists(tmp_dir):
|
|
|
|
| 70 |
tmp_dir = "."
|
| 71 |
|
| 72 |
# Generate unique filenames and paths
|
|
|
|
| 128 |
with open(card_path, "rb") as f:
|
| 129 |
st.download_button("Download Story Card", f, file_name=card_filename)
|
| 130 |
st.image(card_path, caption="Your Story Card", use_container_width=True)
|
|
|
|
| 131 |
st.success("Story card generated!")
|
| 132 |
except Exception as e:
|
| 133 |
st.error(f"Story card generation failed: {e}")
|
|
|
|
| 139 |
st.success("Files uploaded to MEGA successfully!")
|
| 140 |
st.audio(audio_url)
|
| 141 |
st.markdown(f"[Download Audio]({audio_url})")
|
| 142 |
+
st.image(card_url, caption="Your Story Card", use_container_width=True)
|
| 143 |
st.markdown(f"[Download Card]({card_url})")
|
| 144 |
except Exception as e:
|
| 145 |
st.error(f"Failed to upload files to MEGA: {e}")
|