-
Notifications
You must be signed in to change notification settings - Fork 39
/
Home.py
108 lines (91 loc) · 4.5 KB
/
Home.py
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
import streamlit as st
import os
from dotenv import load_dotenv
load_dotenv('.env')
from mongo_auth import Authenticate
from utils import *
import webbrowser
import numpy as np
import pandas as pd
import openai
# Set Streamlit page configuration
st.set_page_config(page_title="SaaS", page_icon=":house", layout="centered", initial_sidebar_state="auto", menu_items=None)
# Load environment variables
# Display the main title
st.markdown('# Your SaaS App')
# Initialize the authenticator
st.session_state['authenticator'] = Authenticate("coolcookiesd267", "keyd3214", 60)
# Set default session state values if not already set
if 'authentication_status' not in st.session_state:
st.session_state['authentication_status'] = None
if 'verified' not in st.session_state:
st.session_state['verified'] = None
# Handle login if not authenticated and not verified
if not st.session_state['authentication_status'] and not st.session_state['verified']:
st.session_state['authenticator'].login('Login', 'main')
if 'summarized_text' not in st.session_state:
st.session_state['summarized_text'] = ''
if 'translation' not in st.session_state:
st.session_state['translation'] = ''
# Handle actions for verified and authenticated users
if st.session_state['verified'] and st.session_state["authentication_status"]:
st.session_state['authenticator'].logout('Logout', 'sidebar', key='123')
openai.api_key = os.environ["OPENAI_API_KEY"]
client = openai.Client(api_key=os.environ["OPENAI_API_KEY"])
# Check if the user's email is subscribed
st.session_state['subscribed'] = is_email_subscribed(st.session_state['email'])
# Display subscription status
if st.session_state.get('subscribed'):
st.write('You are subscribed!')
else:
st.write('You are not subscribed!')
# Free Tool
st.write('This tool is free to use!')
input1 = st.text_area('Enter your text to summarize here:')
if st.button('Summarize') and input1 and input1 != '':
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{'role': 'system', 'content': f'You are a helpful assistant.'},
{"role": "user", "content": f"Provide a summary of the following content: \n ```{input1}```"}
],
temperature=0.0)
st.session_state['summarized_text'] = response.choices[0].message.content
st.write(st.session_state['summarized_text'])
# Subscription-only Tool
st.write('Subscription Only Tool')
st.write('Special tool only subscribers can use!')
input2 = st.text_area('Enter your text to translate here:')
language = st.text_input('Enter the language you want to translate to:')
if st.button('Translate') and input2 and language and input2 != '' and language != '':
if not st.session_state.get('subscribed'):
st.error('Please subscribe to use this tool!')
st.link_button('Subscribe', os.getenv('STRIPE_PAYMENT_URL'))
#webbrowser.open_new_tab()
else:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{'role': 'system', 'content': f'You are a helpful assistant.'},
{"role": "user", "content": f"Translate the text below to the language {language}: \n INPUT: ```{input2}```"}
],
temperature=0.0)
st.write(response)
st.session_state['translation'] = response.choices[0].message.content
st.write(st.session_state['translation'])
# Handle actions for users with correct password but unverified email
elif st.session_state["authentication_status"] == True:
st.error('Your password was correct, but your email has not been not verified. Check your email for a verification link. After you verify your email, refresh this page to login.')
# Add a button to resend the email verification
if st.session_state.get('email'):
if st.button(f"Resend Email Verification to {st.session_state['email']}"):
resend_verification(st.session_state['email'])
# Handle actions for users with incorrect login credentials
elif st.session_state["authentication_status"] == False:
st.error('Username/password is incorrect or does not exist. Reset login credential or register below.')
forgot_password()
register_new_user()
# Handle actions for new users or users with no authentication status
elif st.session_state["authentication_status"] == None:
st.warning('New to SaaS app? Register below.')
register_new_user()