Spaces:
Running
Running
File size: 8,005 Bytes
cead143 1a8a86c 4862dc2 28cb32b 2f686d1 28cb32b 4862dc2 28cb32b 4862dc2 28cb32b 4862dc2 28cb32b 1a8a86c d89edc0 1a8a86c d89edc0 1a8a86c d89edc0 1a8a86c d89edc0 1a8a86c d89edc0 1a8a86c d89edc0 1a8a86c 2f81155 1a8a86c d89edc0 2f81155 1a8a86c d89edc0 1a8a86c d89edc0 2f81155 1a8a86c 4862dc2 79d2b6a 4862dc2 edfc9c4 c187d44 edfc9c4 d80d56f edfc9c4 4aefbe4 edfc9c4 d80d56f edfc9c4 4862dc2 edfc9c4 d80d56f edfc9c4 d80d56f edfc9c4 d80d56f edfc9c4 150cfea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
import streamlit as st
import requests
import streamlit.components.v1 as components
from gtts import gTTS
import os
from io import BytesIO
# νμ΄μ§ μ€μ
st.set_page_config(page_title="ViDraft", layout="wide")
# μ¬μ΄λλ° νμ΄ν μ€μ
st.sidebar.title("ViDraft")
# λ©λ΄ λ° νμ λ©λ΄ μ μ
menus = {
"Home": [],
"Free Stock": ["Template Video", "Search Video", "Search Image"],
"Image": ["Generation", "Face ID", "Inpainting", "Remove Background", "Studio"],
"Video": ["Generation", "Talking Face", "Remove Background", "Studio"],
"Sound": ["Video SFX", "Video Music", "TTS(Voice)", "Image SFX", "Image Music"],
"Scripts": []
}
# μΈμ
μν μ΄κΈ°ν
if 'current_menu' not in st.session_state:
st.session_state['current_menu'] = 'Home'
if 'current_sub_menu' not in st.session_state:
st.session_state['current_sub_menu'] = ''
# λ©μΈ λ©λ΄ μ ν - μ€λ³΅ μ κ±° ν νλλ§ λ¨κΉ
selected_menu = st.sidebar.selectbox("Menu", list(menus.keys()), key='main_menu')
st.session_state['current_menu'] = selected_menu
# νμ λ©λ΄ μ ν (ν΄λΉλλ κ²½μ°)
if selected_menu in menus:
# `key` μΈμμ `selected_menu` κ°μ μ¬μ©νμ¬ κ³ μ ν ν€λ₯Ό μμ±
selected_sub_menu = st.sidebar.selectbox("Sub Menu", [""] + menus[selected_menu], key=f'sub_menu_{selected_menu}')
st.session_state['current_sub_menu'] = selected_sub_menu
else:
st.session_state['current_sub_menu'] = ''
# μ¬κΈ°μλΆν° `selected_menu` λ³μλ₯Ό κΈ°λ°μΌλ‘ 쑰건문μ μ¬μ©νλ λλ¨Έμ§ μ½λκ° μ¬λ°λ₯΄κ² μλν κ²μ
λλ€.
# Pexels API ν€ μ€μ
PEXELS_API_KEY = "5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62"
def search_images(keyword, per_page=80):
"""μ΄λ―Έμ§ κ²μ ν¨μ"""
url = f"https://api.pexels.com/v1/search?query={keyword}&per_page={per_page}"
headers = {"Authorization": PEXELS_API_KEY}
response = requests.get(url, headers=headers).json()
images = []
if 'photos' in response:
for photo in response['photos']:
images.append(photo['src']['original'])
return images
def search_videos(keyword, per_page=80):
"""λΉλμ€ κ²μ ν¨μ"""
url = f"https://api.pexels.com/videos/search?query={keyword}&per_page={per_page}"
headers = {"Authorization": PEXELS_API_KEY}
response = requests.get(url, headers=headers).json()
videos = []
if 'videos' in response:
for video in response['videos']:
videos.append(video['video_files'][0]['link'])
return videos
# 'Search Image' μ ν μ
if selected_menu == "Free Stock" and st.session_state['current_sub_menu'] == "Search Image":
keyword = st.text_input("Enter a keyword to search for images")
if keyword:
images = search_images(keyword)
cols = st.columns(3) # 3μ΄λ‘ μ΄λ―Έμ§ νμ
for idx, img in enumerate(images):
with cols[idx % 3]:
st.image(img)
# 'Search Video' μ ν μ
if selected_menu == "Free Stock" and st.session_state['current_sub_menu'] == "Search Video":
keyword = st.text_input("Enter a keyword to search for videos")
if keyword:
videos = search_videos(keyword)
cols = st.columns(3) # 3μ΄λ‘ λΉλμ€ νμ
for idx, video in enumerate(videos):
with cols[idx % 3]:
st.video(video)
# 'Image' λ©λ΄μμ 'Remove Background' μ ν μ
if selected_menu == "Image" and st.session_state['current_sub_menu'] == "Remove Background":
st.header("Remove Background")
# iframeμ μ¬μ©νμ¬ μΈλΆ URL μλ² λ
components.iframe("https://seawolf2357-gttstest.hf.space", width=None, height=600, scrolling=True)
# 'Sound' λ©λ΄μ 'TTS(Voice)' μ ν μ
if st.sidebar.selectbox("Menu", list(menus.keys())) == "Sound":
if st.sidebar.selectbox("Sub Menu", menus["Sound"]) == "TTS(Voice)":
st.header("Text-to-Speech")
# ν
μ€νΈ μ
λ ₯
text = st.text_area("Enter text to synthesize", "Hello, welcome to ViDraft TTS service.")
# μΈμ΄ μ ν
language = st.selectbox("Choose Language", ["en", "es", "de", "fr", "it", "pt", "ru", "ja", "ko", "zh-cn", "zh-tw"])
# 'Synthesize' λ²νΌ
if st.button("Synthesize"):
if text:
try:
tts = gTTS(text=text, lang=language, slow=False)
audio_file = BytesIO()
tts.write_to_fp(audio_file)
audio_file.seek(0)
st.audio(audio_file, format='audio/mp3')
except Exception as e:
st.error(f"Error: {e}")
else:
st.warning("Please enter some text to synthesize.")
# 'Home' νμ΄μ§ νμ
if selected_menu == "Home":
st.header("Welcome to ViDraft")
st.write("Choose an option from the sidebar to get started.")
elif selected_menu == "Free Stock":
# 'Free Stock' λ©λ΄ μ ν μ μ²λ¦¬ λ‘μ§
if st.session_state['current_sub_menu'] == "Template Video":
st.header("Template Videos")
st.write("Explore a variety of video templates.")
# λΉλμ€ νμΌ κ²½λ‘ μ€μ λ° λΉλμ€ νμ λ‘μ§
video_files = ["ex1.mp4", "ex2.mp4", "ex3.mp4", "ex4.mp4", "ex5.mp4", "ex6.mp4", "ex7.mp4", "ex8.mp4", "ex9.mp4", "ex10.mp4", "ex11.mp4", "ex12.mp4", "ex13.mp4", "ex14.mp4", "ex15.mp4", "ex16.mp4", "ex17.mp4", "ex18.mp4"]
# κ°€λ¬λ¦¬ ννλ‘ λΉλμ€ νμ
cols = st.columns(2) # 2κ°μ μ΄λ‘ λκ² λ°°μΉ
for index, video_file in enumerate(video_files):
with cols[index % 2]:
st.video(video_file)
# 'Image' λ©λ΄ μ ν μ μ²λ¦¬ λ‘μ§
elif selected_menu == "Image":
if st.session_state['current_sub_menu'] == "Generation":
st.header("Image Generation")
st.write("Generate images using AI.")
elif st.session_state['current_sub_menu'] == "Face ID":
st.header("Face ID")
st.write("Identify and analyze faces in images.")
elif st.session_state['current_sub_menu'] == "Inpainting":
st.header("Inpainting")
st.write("Fill in missing parts of images.")
elif st.session_state['current_sub_menu'] == "Studio":
st.header("Image Studio")
st.write("Access a suite of image editing tools.")
# 'Video' λ©λ΄ μ ν μ μ²λ¦¬ λ‘μ§
elif selected_menu == "Video":
if st.session_state['current_sub_menu'] == "Generation":
st.header("Video Generation")
st.write("Create videos with our generation tools.")
elif st.session_state['current_sub_menu'] == "Talking Face":
st.header("Talking Face Videos")
st.write("Generate talking face videos from images.")
elif st.session_state['current_sub_menu'] == "Remove Background":
st.header("Video Background Removal")
st.write("Remove backgrounds from your videos effortlessly.")
elif st.session_state['current_sub_menu'] == "Studio":
st.header("Video Studio")
st.write("Explore our video editing studio for advanced editing.")
# 'Sound' λ©λ΄ μ ν μ μ²λ¦¬ λ‘μ§
elif selected_menu == "Sound":
if st.session_state['current_sub_menu'] == "Video SFX":
st.header("Video Sound Effects")
st.write("Enhance your videos with sound effects.")
elif st.session_state['current_sub_menu'] == "Video Music":
st.header("Video Music")
st.write("Find the perfect music for your video content.")
elif st.session_state['current_sub_menu'] == "Image SFX":
st.header("Image Sound Effects")
st.write("Add sound effects to your images.")
elif st.session_state['current_sub_menu'] == "Image Music":
st.header("Image Music")
st.write("Associate music tracks with your images.")
# 'Scripts' λ©λ΄ μ ν μ μ²λ¦¬ λ‘μ§
elif selected_menu == "Scripts":
st.header("Scripts")
st.write("Script writing tools and resources.") |