Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import openai | |
| from PIL import Image | |
| import os | |
| import streamlit_tags as stt | |
| api_key = os.environ['open_ai_api'] | |
| bot_role = os.environ['bot_role'] | |
| openai.api_key = api_key | |
| st.set_page_config( page_title="App by Adam", page_icon=":fork_and_knife:") | |
| messages = [ | |
| {"role": "system", "content": bot_role}, | |
| ] | |
| # List of suggested questions | |
| suggested_questions = [ | |
| "Three breakfast recipes", | |
| "Mcdonalds for lunch", | |
| "Cancer fighting foods", | |
| "Food and nutrition myths", | |
| "Pakistan dinner recipes", | |
| "I have a lot of belly fat", | |
| "Gas station food", | |
| "Grocery shopping list" | |
| ] | |
| def chatbot(input): | |
| if input: | |
| messages.append({"role": "user", "content": input}) | |
| chat = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", messages=messages | |
| ) | |
| reply = chat.choices[0].message.content | |
| messages.append({"role": "assistant", "content": reply}) | |
| return reply | |
| # Center the text and enlarge the font | |
| st.markdown("<h1 style='text-align: center; font-size: 60px;'> Adam </h1>", unsafe_allow_html=True) | |
| st.markdown("<h1 style='text-align: center; font-size: 46px;'> Your Healthy Keto expert π€</h1>", unsafe_allow_html=True) | |
| st.markdown("<h1 style='text-align: center; font-size: 36px;'>Ask me about food π, nutrition π, and illness π€</h1>", unsafe_allow_html=True) | |
| # Create an expander for the chat content | |
| with st.expander("Chat"): | |
| question = stt.st_tags( | |
| label='Please write your question:', | |
| text='Write your question and hit enter ..', | |
| # value=suggested_questions, | |
| suggestions= suggested_questions, | |
| maxtags = 1, | |
| key='1') | |
| if len(question) > 0: | |
| input_text = question[0] | |
| # Center and enlarge the send button | |
| col1, col2, col3 = st.columns([1, 3, 1]) | |
| with col2: | |
| send = st.button("Send", key="send") | |
| if send: | |
| if len(question) > 0: | |
| response = chatbot(input_text) | |
| st.write(response) | |
| else: | |
| st.write("Write question") | |