DatabricksComp/DatabricksBackendSpace
0
1import streamlit as st2 3import pathlib4import textwrap5import requests6import google.generativeai as genai7import json8import os9 10 11 12# VIDEO_URL = "https://example.com/not-youtube.mp4"13# st.video(VIDEO_URL)14 15def getSongUrl(title):16 url = "https://mothersuno-api.vercel.app/api/get?id"17 response = requests.get(url)18 response.json()19 for i in range(len(response.json())):20 if (response.json()[i]['title'] == title):21 return response.json()[i]['audio_url']22 23def generate_audio(lyrics, genre, title):24 url = "https://mothersuno-api.vercel.app/api/custom_generate"25 payload = {"prompt": lyrics, "tags" : genre, "title" : str(title), "make_instrumental": False, "wait_audio": False}26 response = requests.post(url,json=payload)27 return response.text28 29# print(str(title))30# print(lyrics)31# print(genre)32 33 34 35st.set_page_config(page_title="Syntheo", page_icon=":robot:")36st.header("Syntheo")37 38if "generated" not in st.session_state:39 st.session_state["generated"] = []40 41if "past" not in st.session_state:42 st.session_state["past"] = []43 44if "messages" not in st.session_state:45 st.session_state["messages"] = []46 47init_alr = False48 49def init_model(user_input):50 os.environ["API_KEY"] = "AIzaSyAgqODyVqcqlsDC1Gzuy8TkpiWnQZVGovw"51 genai.configure(api_key=os.environ.get("API_KEY"))52 model = genai.GenerativeModel('gemini-pro')53 54 userInput = user_input #"Give me an afrofunk beat along with a cool melody and catchy drums, along with an opera style"55 prompt = userInput + ". Output ONLY the specific music genre that the user would like that fits their requirements, with no excess words. NO APOSTROPHES. Add more than one genre to best fit the user's prompt. Desired Output: <all_lowercase_comma_separated_genres>"56 response = model.generate_content(prompt)57 genre = response.text58 59 userInput = "Genre: " + genre + ". Generate lyrics that would best fit into the required genre. Generate around 2 minutes worth of lyrics. Separate verses using [Verse #] and NO APOSTROPHES AT ALL. Desired Format: <seperate_each_verse_no_asteriks_or_apostrophes>"60 response = model.generate_content(userInput)61 lyrics = response.text62 63 lyricInput = "Lyrics: " + lyrics[:25] + ". Based upon the following lyrics, please generate a title for this song. Desired Format: <title_case_without_genre>"64 response = model.generate_content(lyricInput)65 title = response.text66 67 # userInput = "Lyrics: " + lyrics + ". Split the following lyrics into ONLY 10 slices with each slice enhanced to describe a music video. You may slightlly alter the lyrics to best cater to this requirment. Each section is separated by a |. Use only 10 |'s. Delete ALL \n characters and Verse seperators as well. Desired Output: <|_separated>"68 # response = model.generate_content(userInput)69 # sepTen = response.text70 # whollySplit = sepTen.split("|")71 72 73 generate_audio(lyrics, genre, title)74 75 #make API request76 audiourl = getSongUrl(title)77 78 #call webscraping script79 #get_mp3("Samba Kickoff")80 81 return title, genre, lyrics, audiourl 82 83#st_callback = StreamlitCallbackHandler(st.container())84 85 86 87if prompt := st.chat_input():88 st.chat_message("user").write(prompt)89 with st.chat_message("assistant"):90 #st_callback = StreamlitCallbackHandler(st.container())91 92 if init_alr == False:93 init_alr = True94 95 title, genre, lyrics, audiourl = init_model(prompt)96 #Call query generator with text_input97 #query = prompty(date_input, prompt)98 #result = qa({"query": query})99 100 st.write('Based on the interesting description you have provided, we will generate a ' + genre + ' music experience for you:')101 st.write('Title: ' + title)102 st.write('Lyrics: ' + lyrics)103 st.write('You can find the final generated mp4 file here: ' + audiourl)104 st.stop()105 