2023-04-27 12:12:04 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir))
|
|
|
|
|
2023-04-24 15:52:44 +00:00
|
|
|
import streamlit as st
|
2023-04-29 09:25:24 +00:00
|
|
|
from gpt4free import you
|
2023-04-27 19:10:43 +00:00
|
|
|
|
2023-04-27 01:12:33 +00:00
|
|
|
|
|
|
|
def get_answer(question: str) -> str:
|
|
|
|
# Set cloudflare clearance cookie and get answer from GPT-4 model
|
2023-04-25 08:11:31 +00:00
|
|
|
try:
|
2023-04-27 19:10:43 +00:00
|
|
|
result = you.Completion.create(prompt=question)
|
|
|
|
|
|
|
|
return result.text
|
|
|
|
|
2023-04-25 08:11:31 +00:00
|
|
|
except Exception as e:
|
2023-04-27 01:12:33 +00:00
|
|
|
# Return error message if an exception occurs
|
2023-04-27 19:10:43 +00:00
|
|
|
return (
|
|
|
|
f'An error occurred: {e}. Please make sure you are using a valid cloudflare clearance token and user agent.'
|
|
|
|
)
|
2023-04-27 01:12:33 +00:00
|
|
|
|
2023-04-24 15:52:44 +00:00
|
|
|
|
2023-04-27 01:12:33 +00:00
|
|
|
# Set page configuration and add header
|
2023-04-24 15:52:44 +00:00
|
|
|
st.set_page_config(
|
|
|
|
page_title="gpt4freeGUI",
|
|
|
|
initial_sidebar_state="expanded",
|
|
|
|
page_icon="🧠",
|
|
|
|
menu_items={
|
|
|
|
'Get Help': 'https://github.com/xtekky/gpt4free/blob/main/README.md',
|
|
|
|
'Report a bug': "https://github.com/xtekky/gpt4free/issues",
|
2023-04-27 19:10:43 +00:00
|
|
|
'About': "### gptfree GUI",
|
|
|
|
},
|
2023-04-24 15:52:44 +00:00
|
|
|
)
|
|
|
|
st.header('GPT4free GUI')
|
|
|
|
|
2023-04-27 01:12:33 +00:00
|
|
|
# Add text area for user input and button to get answer
|
2023-04-27 19:10:43 +00:00
|
|
|
question_text_area = st.text_area('🤖 Ask Any Question :', placeholder='Explain quantum computing in 50 words')
|
2023-04-24 15:52:44 +00:00
|
|
|
if st.button('🧠 Think'):
|
2023-04-27 01:12:33 +00:00
|
|
|
answer = get_answer(question_text_area)
|
2023-04-28 07:41:07 +00:00
|
|
|
escaped = answer.encode('utf-8').decode('unicode-escape')
|
2023-04-27 01:12:33 +00:00
|
|
|
# Display answer
|
2023-04-24 15:52:44 +00:00
|
|
|
st.caption("Answer :")
|
2023-04-28 07:41:07 +00:00
|
|
|
st.markdown(escaped)
|
2023-04-24 15:52:44 +00:00
|
|
|
|
2023-04-27 01:12:33 +00:00
|
|
|
# Hide Streamlit footer
|
2023-04-24 15:52:44 +00:00
|
|
|
hide_streamlit_style = """
|
|
|
|
<style>
|
|
|
|
footer {visibility: hidden;}
|
|
|
|
</style>
|
|
|
|
"""
|
2023-04-27 01:12:33 +00:00
|
|
|
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|