import streamlit as st import requests import streamlit.components.v1 as components from gtts import gTTS from gtts.lang import tts_langs from io import BytesIO import os # 페이지 설정 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: 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'] = '' # 'Sound' 메뉴의 'TTS(Voice)' 선택 시 if selected_menu == "Sound" and selected_sub_menu == "TTS(Voice)": st.header("Text-to-Speech") # 텍스트 입력 text = st.text_area("Enter text to synthesize", "Hello, welcome to ViDraft TTS service.") # 지원되는 언어 목록을 불러옵니다. languages_dict = tts_langs() # ISO 639-1 표준에 따라 두 글자 코드를 가진 언어만 필터링 two_letter_languages = {code: lang for code, lang in languages_dict.items() if len(code) == 2} # 언어 선택을 위한 selectbox를 생성합니다. selected_language_code = st.selectbox( "Choose Language", options=list(two_letter_languages.keys()), format_func=lambda x: f"{two_letter_languages[x]} ({x})", index=list(two_letter_languages.keys()).index('en') # 'en'을 기본 언어로 설정 ) # 'Synthesize' 버튼 if st.button("Synthesize"): if text: try: # 선택된 언어로 gTTS 객체 생성 tts = gTTS(text=text, lang=selected_language_code, 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.") # 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) # 'Home' 페이지 표시 if selected_menu == "Home": st.image("banner.jpg", use_column_width=True) st.header("Welcome to ViDraft") # 환영 메시지 및 서비스 설명 welcome_text = """ Welcome to our dynamic platform, where creativity meets technology across a vast spectrum of multimedia services. Our service offers an extensive array of options for every multimedia need: - **Home**: Start your journey here with us, where innovation meets functionality. - **Free Stock**: Dive into our rich collection of template videos, search for the perfect video or image to complement your project. - **Image**: Explore our advanced image services including AI-powered generation, facial recognition, inpainting, background removal, and our comprehensive image studio. - **Video**: Unleash your creativity with video generation, talking face animations, background removal, and access to our state-of-the-art video studio. - **Sound**: Enhance your projects with video sound effects (SFX), curated video music, text-to-speech (TTS) services, image SFX, and image music integration. - **Scripts**: Access a wide range of scripting tools and resources to bring your stories to life. Join us to transform your creative ideas into reality with cutting-edge technology designed for creators, by creators. """ st.write(welcome_text) # 이미지들을 한 줄에 배치 cols = st.columns(4) # 4개의 열 생성 image_files = [ "ViDraft-Video-Templet.png", "ViDraft-Video-search.png", "ViDraft-Image-search.png", "ViDraft-TTS.png" ] image_texts = [ "Video Template", "Video Search", "Image Search", "TTS (Voice)" ] for col, img_file, img_text in zip(cols, image_files, image_texts): with col: st.image(img_file, use_column_width=True) st.caption(img_text) # 파일명을 통해 이미지 아래 텍스트 반영 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 crafted with the innovative technology of OpenAI SORA. Dive into an immersive experience with samples generated by the cutting-edge AI, showcasing the potential to transform your creative ideas into captivating visual stories.") # 비디오 파일 경로 설정 및 비디오 표시 로직 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.")