Spaces:
Sleeping
Sleeping
ogeti siva satyanarayana
commited on
Commit
Β·
1ac057d
1
Parent(s):
ebc47e3
Update streamlit_ui.py
Browse files- streamlit_ui.py +27 -7
streamlit_ui.py
CHANGED
|
@@ -2,18 +2,19 @@
|
|
| 2 |
import streamlit as st
|
| 3 |
import requests
|
| 4 |
import base64
|
|
|
|
|
|
|
| 5 |
|
| 6 |
st.set_page_config(
|
| 7 |
page_title="Prompta - Text to Media Generator",
|
| 8 |
-
page_icon="ποΈ",
|
| 9 |
layout="wide",
|
| 10 |
initial_sidebar_state="expanded"
|
| 11 |
)
|
| 12 |
st.title("ποΈπΌοΈποΈ Prompta - Text to Media Generator")
|
| 13 |
|
| 14 |
-
API_BASE = "http://localhost:8000"
|
| 15 |
|
| 16 |
-
# Helper to play audio/video in Streamlit
|
| 17 |
def render_media(file_bytes, media_type, label):
|
| 18 |
b64 = base64.b64encode(file_bytes).decode()
|
| 19 |
if media_type == "audio":
|
|
@@ -23,19 +24,17 @@ def render_media(file_bytes, media_type, label):
|
|
| 23 |
elif media_type == "image":
|
| 24 |
st.image(file_bytes, caption=label, use_column_width=True)
|
| 25 |
|
| 26 |
-
# Sidebar inputs
|
| 27 |
st.sidebar.header("π οΈ Settings")
|
| 28 |
TOKEN = st.sidebar.text_input("π API Token", type="password")
|
| 29 |
HEADERS = {"Authorization": f"Bearer {TOKEN}"} if TOKEN else {}
|
| 30 |
|
| 31 |
-
# Tabs
|
| 32 |
tab = st.sidebar.radio("Select Task", ["Text to Audio", "Text to Image", "Text to Video"])
|
| 33 |
|
| 34 |
if tab == "Text to Audio":
|
| 35 |
st.subheader("π€ Text to Audio")
|
| 36 |
text = st.text_area("Enter text")
|
| 37 |
voice = st.selectbox("Choose voice/language", ["en-US", "hi-IN", "te-IN", "ta-IN"])
|
| 38 |
-
|
| 39 |
if st.button("π Generate Audio"):
|
| 40 |
with st.spinner("Generating audio..."):
|
| 41 |
r = requests.post(f"{API_BASE}/audio/generate", json={"text": text, "voice": voice}, headers=HEADERS)
|
|
@@ -64,6 +63,9 @@ elif tab == "Text to Video":
|
|
| 64 |
domain = st.selectbox("Domain", ["health", "education", "governance", "entertainment"])
|
| 65 |
environment = st.selectbox("Environment", ["urban", "rural", "nature", "futuristic"])
|
| 66 |
|
|
|
|
|
|
|
|
|
|
| 67 |
if st.button("π¬ Generate Video"):
|
| 68 |
with st.spinner("Generating video..."):
|
| 69 |
r = requests.post(
|
|
@@ -72,7 +74,25 @@ elif tab == "Text to Video":
|
|
| 72 |
headers=HEADERS
|
| 73 |
)
|
| 74 |
if r.status_code == 200:
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
else:
|
| 77 |
st.error(f"β Failed: {r.json().get('detail')}")
|
| 78 |
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import requests
|
| 4 |
import base64
|
| 5 |
+
import tempfile
|
| 6 |
+
from backend.subtitle_utils import generate_srt_from_text, enhance_video_with_subtitles_and_bgm
|
| 7 |
|
| 8 |
st.set_page_config(
|
| 9 |
page_title="Prompta - Text to Media Generator",
|
| 10 |
+
page_icon="ποΈ",
|
| 11 |
layout="wide",
|
| 12 |
initial_sidebar_state="expanded"
|
| 13 |
)
|
| 14 |
st.title("ποΈπΌοΈποΈ Prompta - Text to Media Generator")
|
| 15 |
|
| 16 |
+
API_BASE = "http://localhost:8000"
|
| 17 |
|
|
|
|
| 18 |
def render_media(file_bytes, media_type, label):
|
| 19 |
b64 = base64.b64encode(file_bytes).decode()
|
| 20 |
if media_type == "audio":
|
|
|
|
| 24 |
elif media_type == "image":
|
| 25 |
st.image(file_bytes, caption=label, use_column_width=True)
|
| 26 |
|
|
|
|
| 27 |
st.sidebar.header("π οΈ Settings")
|
| 28 |
TOKEN = st.sidebar.text_input("π API Token", type="password")
|
| 29 |
HEADERS = {"Authorization": f"Bearer {TOKEN}"} if TOKEN else {}
|
| 30 |
|
|
|
|
| 31 |
tab = st.sidebar.radio("Select Task", ["Text to Audio", "Text to Image", "Text to Video"])
|
| 32 |
|
| 33 |
if tab == "Text to Audio":
|
| 34 |
st.subheader("π€ Text to Audio")
|
| 35 |
text = st.text_area("Enter text")
|
| 36 |
voice = st.selectbox("Choose voice/language", ["en-US", "hi-IN", "te-IN", "ta-IN"])
|
| 37 |
+
|
| 38 |
if st.button("π Generate Audio"):
|
| 39 |
with st.spinner("Generating audio..."):
|
| 40 |
r = requests.post(f"{API_BASE}/audio/generate", json={"text": text, "voice": voice}, headers=HEADERS)
|
|
|
|
| 63 |
domain = st.selectbox("Domain", ["health", "education", "governance", "entertainment"])
|
| 64 |
environment = st.selectbox("Environment", ["urban", "rural", "nature", "futuristic"])
|
| 65 |
|
| 66 |
+
transcript = st.text_area("Transcript (optional - for subtitles)", height=100)
|
| 67 |
+
enhance = st.checkbox("β¨ Add Subtitles and Background Music")
|
| 68 |
+
|
| 69 |
if st.button("π¬ Generate Video"):
|
| 70 |
with st.spinner("Generating video..."):
|
| 71 |
r = requests.post(
|
|
|
|
| 74 |
headers=HEADERS
|
| 75 |
)
|
| 76 |
if r.status_code == 200:
|
| 77 |
+
video_bytes = r.content
|
| 78 |
+
if enhance and transcript:
|
| 79 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_vid:
|
| 80 |
+
tmp_vid.write(video_bytes)
|
| 81 |
+
tmp_vid_path = tmp_vid.name
|
| 82 |
+
|
| 83 |
+
srt_path = generate_srt_from_text(transcript, output_path="streamlit_subs.srt")
|
| 84 |
+
enhanced_path = "streamlit_final_video.mp4"
|
| 85 |
+
enhance_video_with_subtitles_and_bgm(
|
| 86 |
+
video_path=tmp_vid_path,
|
| 87 |
+
srt_path=srt_path,
|
| 88 |
+
bgm_path="default_bgm.mp3",
|
| 89 |
+
output_path=enhanced_path
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
with open(enhanced_path, "rb") as f:
|
| 93 |
+
render_media(f.read(), "video", "Enhanced Video")
|
| 94 |
+
else:
|
| 95 |
+
render_media(video_bytes, "video", "Generated Video")
|
| 96 |
else:
|
| 97 |
st.error(f"β Failed: {r.json().get('detail')}")
|
| 98 |
|