forked from awsaruna/streamlit-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
95 lines (87 loc) · 3.79 KB
/
Copy pathstreamlit_app.py
File metadata and controls
95 lines (87 loc) · 3.79 KB
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
from collections import namedtuple
import altair as alt
import math
import pandas as pd
import streamlit as st
import openai
from gtts import gTTS
import base64
st.markdown("""
<style>
body {
background-color: #f5ebff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
div.main {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
.stApp, .css-145kmo2, .css-17eq0hr, .css-qbe2hs, .css-1aumxhk, .css-17y0c9n, .css-1v3fh75, .css-t8sg0s, .css-1dbjc4n {
color: #8000ff !important;
}
.footer {
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
font-size: 5px;
}
/* Style the submit button */
.stButton > button {
background-color: #8000ff !important;
color: white !important;
}
/* Style the text box border */
input[type="text"] {
border: 1px solid #8000ff !important;
}
}
/* Style the submit button border */
.stButton > button {
border: 1px solid #8000ff !important;
}
</style>
""", unsafe_allow_html=True)
st.image("https://e2009.s3.us-west-1.amazonaws.com/Untitled+Oct+04.png", width=200)
st.markdown("""# TeenTalk""")
st.markdown("""#### Made by Karthick Arun""")
st.divider()
# Setting the API key
openai.api_key = st.secrets["API_KEY"]
user_input = st.text_input("Your life is very precious, you can make a difference in the world. I am here for you....", placeholder="please type what your concerns here, I am here to help.")
if st.button("Submit", type="primary"):
#prompt = "Check the sentiment of the following phrase and if its negative then convert it to a positive phrase, start with a very supportive and understanding tone\n\nDesired format:Original Phrase:,Sentiment:,Converted Phrase:\n\nText:'"+user_input+"'"
prompt = "You are a student councelor with very deep compasion, you are a the trusted adult. Check the sentiment of the following phrase and if its negative then advise the student in an encouraging tone. Start with a very supportive and understanding tone. If any topics of suicide or self harm to others or the user then refer them to the teen suicide help hotline phone or text numeber. Just say the advise and no additional information\n\nText:'"+user_input+"'"
# Create a chatbot using ChatCompletion.create() function
completion = openai.ChatCompletion.create(
# Use GPT 3.5 as the LLM
model="gpt-3.5-turbo",
# Pre-define conversation messages for the possible roles
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
)
# Print the returned output from the LLM model
# print(completion.choices[0].message)
st.write(completion.choices[0].message["content"])
tts = gTTS(completion.choices[0].message["content"], lang="en", slow=False)
tts.save("output.mp3")
st.audio("output.mp3", format='audio/mp3')
st.markdown("""
<style>
.small-font {
font-size: 0.8em;
}
</style>
<div class="small-font">
**Disclaimer:** This web app is powered by experimental AI technology. It is not a substitute for professional mental health advice or treatment. It is not licensed, nor should it be used for addressing serious mental health issues related to suicide or other severe diagnoses. If you or someone you know is in crisis or needs immediate help, please dial the international crisis helpline at **988** and consult with a trusted adult or mental health professional.
</div>
""", unsafe_allow_html=True)
# Define the user prompt message
#prompt = "Say the following sentence in a very positive and constructive way, start with a very supportive and understanding tone:'you look ugly and stupid'"