ayaht commited on
Commit
149728f
Β·
verified Β·
1 Parent(s): cdbfddb

Upload 4 files

Browse files
music_recommendations.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ import scipy.io.wavfile
4
+ from openai import OpenAI
5
+ import time
6
+ import numpy as np
7
+
8
+ # Initialize the OpenAI client
9
+ client = OpenAI(
10
+ api_key="a99ae8e15f1e439a935b5e1cf2005c8b",
11
+ base_url="https://api.aimlapi.com",
12
+ )
13
+
14
+ # Streamlit app layout
15
+ st.title("Mood-based Music Generator")
16
+
17
+ # Ask the user for their feeling and preferred music style via Streamlit inputs
18
+ user_feeling = st.text_input("How are you feeling right now?", value="feeling down")
19
+ music_style = st.text_input("What music style do you prefer?", value="pop")
20
+
21
+ # Button to trigger music generation
22
+ if st.button("Generate Music"):
23
+ with st.spinner("Generating music, please wait..."):
24
+ # Send the feeling and music style to the OpenAI model
25
+ response = client.chat.completions.create(
26
+ model="meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo",
27
+ messages=[
28
+ {
29
+ "role": "system",
30
+ "content": "You are a musical assistant that, based on a user's feeling, can describe it as a musical instrument. Provide a short one-sentence response."
31
+ },
32
+ {
33
+ "role": "user",
34
+ "content": f"I am feeling {user_feeling}. Can you make me happy with a {music_style} style of music?"
35
+ },
36
+ ],
37
+ )
38
+
39
+ message = response.choices[0].message.content
40
+ st.write(f"Assistant: {message}")
41
+
42
+ # Load the synthesizer model for music generation
43
+ synthesiser = pipeline("text-to-audio", "facebook/musicgen-small")
44
+
45
+ # Simulate a short wait to represent loading time for music generation
46
+ time.sleep(2)
47
+
48
+ # Generate the music using the synthesizer model based on the message
49
+ music = synthesiser(message, forward_params={"do_sample": True, "guidance_scale": 1})
50
+
51
+ # Save the generated audio to a file
52
+ audio_filename = "musicgen_out.wav"
53
+ scipy.io.wavfile.write(audio_filename, rate=music["sampling_rate"], data=np.array(music["audio"]))
54
+
55
+ st.success("Music has been generated!")
56
+
57
+ # Play the generated audio in Streamlit
58
+ st.audio(audio_filename)
59
+
physical_activity.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from openai import OpenAI
3
+
4
+ # Initialize the OpenAI client
5
+ client = OpenAI(
6
+ api_key="9a70a7b82dd84c8cb2e8c43a156be3c7", # Replace with your actual API key
7
+ base_url="https://api.aimlapi.com", # Replace with the correct base URL if needed
8
+ )
9
+
10
+ # Streamlit page title
11
+ st.title("Mood-based Exercise Recommendations")
12
+
13
+ # User input: Ask the user how they feel
14
+ user_feeling = st.text_input("How are you feeling right now?", placeholder="e.g., tired, stressed, happy...")
15
+
16
+ # When the user submits their feeling, generate an exercise recommendation using the model
17
+ if user_feeling:
18
+ with st.spinner("Generating exercise recommendation..."):
19
+ # Send the user's feeling to the OpenAI model
20
+ response = client.chat.completions.create(
21
+ model="meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo",
22
+ messages=[
23
+ {
24
+ "role": "system",
25
+ "content": "You are a fitness coach and a doctor . Based on the user's current mood, suggest a suitable exercise in one sentence. and write them in bullet"
26
+ },
27
+ {
28
+ "role": "user",
29
+ "content": f"I am feeling {user_feeling}. What exercise should I do?"
30
+ },
31
+ ],
32
+ )
33
+
34
+ # Get the model's response
35
+ message = response.choices[0].message.content
36
+
37
+ # Display the exercise recommendation
38
+ st.write(f"Based on how you're feeling, here's an exercise suggestion for you: {message}")
positive_quotes.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary libraries
2
+ from openai import OpenAI
3
+ import streamlit as st
4
+
5
+ # Initialize OpenAI Client
6
+ client = OpenAI(api_key='2051e9263e2e4f0e9afb23afe4a654fa', base_url='https://api.aimlapi.com/')
7
+
8
+ # Define the system prompt
9
+ system_prompt = (
10
+ 'You are a helpful assistant that provides positive, optimistic, uplifting, '
11
+ 'and motivational quotes filled with wisdom, encouragement, and hope to uplift and inspire people.'
12
+ )
13
+
14
+ def generate_positive_quote(feeling):
15
+ # Create a personalized user prompt based on the user's input
16
+ user_prompt = f'Give me a positive quote that can help someone who feels {feeling}.'
17
+
18
+ # Create messages for the API request
19
+ messages = [
20
+ {'role': 'system', 'content': system_prompt},
21
+ {'role': 'user', 'content': user_prompt}
22
+ ]
23
+
24
+ # Call the OpenAI API
25
+ response = client.chat.completions.create(
26
+ model="meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo",
27
+ messages=messages,
28
+ temperature=0.5,
29
+ max_tokens=100
30
+ )
31
+
32
+ # Extract and return the quote from the response
33
+ return response.choices[0].message.content
34
+
35
+
36
+
37
+ # Set up the Streamlit page
38
+ st.title('✨ Positive Quote Generator ✨')
39
+
40
+ st.markdown("Welcome to the Positive Quote Generator! Click the button below to receive an uplifting message.")
41
+ # Input field for the user to describe how they feel
42
+ feeling = st.text_input('How do you feel today?', '')
43
+
44
+ # Generate and display a quote when the button is clicked
45
+ if st.button('Get Positive Quote'):
46
+ if feeling:
47
+ quote = generate_positive_quote(feeling)
48
+ st.success(quote)
49
+ else:
50
+ st.error('Please enter how you feel.')
51
+
talk_to_friend.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from openai import OpenAI
3
+
4
+ # OpenAI Client
5
+ client = OpenAI(api_key='up_CpZjdAyzHNZSbSTAQWVqYuJGgQNJW', base_url='https://api.upstage.ai/v1/solar')
6
+
7
+ # Streamlit page configuration
8
+ st.set_page_config(page_title='Chat with me 😊', layout='wide')
9
+ st.title("Chat with me 😊")
10
+
11
+ # Initialize session state
12
+ if 'messages' not in st.session_state:
13
+ st.session_state.messages = [
14
+ {'role': 'system', 'content': 'You are a helpful friend that someone can depend on and want to chat with, you provides positive, optimistic, uplifting, and motivational suggestions and advices filled with wisdom, encouragement and hope to uplift and inspire people.'}
15
+ ]
16
+
17
+ def generate_response(prompt: str) -> str:
18
+ response = client.chat.completions.create(
19
+ model="solar-pro",
20
+ messages=st.session_state.messages + [{'role': 'user', 'content': prompt}],
21
+ temperature=0.7,
22
+ max_tokens=200
23
+ )
24
+
25
+ return response.choices[0].message.content
26
+
27
+ # Display chat messages
28
+ for message in st.session_state.messages[1:]: # Skip the system message
29
+ with st.chat_message(message['role']):
30
+ st.write(message['content'])
31
+
32
+ # Chat input
33
+ user_input = st.chat_input("I am waiting to hear from you 😊")
34
+
35
+ if user_input:
36
+ if user_input.lower() in ['quit', 'exit', 'escape', 'out', 'ex']:
37
+ st.session_state.messages = [st.session_state.messages[0]] # Keep only the system message
38
+ st.success("Thanks for chatting with me!")
39
+ else:
40
+ # Add user message to chat history
41
+ st.session_state.messages.append({'role': 'user', 'content': user_input})
42
+
43
+ # Display user message
44
+ with st.chat_message("user"):
45
+ st.write(user_input)
46
+
47
+ # Generate bot response
48
+ response = generate_response(user_input)
49
+
50
+ # Add bot response to chat history
51
+ st.session_state.messages.append({'role': 'assistant', 'content': response})
52
+
53
+ # Display bot response
54
+ with st.chat_message("assistant"):
55
+ st.write(response)
56
+
57
+ # No rerun needed