Spaces:
Sleeping
Sleeping
File size: 2,644 Bytes
75ecec3 |
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 |
import streamlit as st
import openai
from googletrans import Translator
# Set up OpenAI API credentials
openai.api_key = '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'
def translate_text(text, target_language):
translator = Translator()
translation = translator.translate(text, dest=target_language)
return translation.text
def get_food_recommendation(prompt):
# Generate a response using the ChatGPT API
response = openai.Completion.create(
engine='text-davinci-003',
prompt=prompt,
max_tokens=500,
n=1,
stop=None,
temperature=0.7
)
# Extract the recommended food from the API response
recommendation = response.choices[0].text.strip()
return recommendation
def korean_text():
st.title("μν λ° μμ κΆμ₯ μμ€ν
")
st.write("μν λ° μμ κΆμ₯ μμ€ν
μ μ€μ κ²μ νμν©λλ€")
st.markdown("μΉνμ΄μ§μμ λμμ΄ λ μ μλ λͺ κ°μ§ μμμ
λλ€:")
st.markdown("- 200μΉΌλ‘리 μμ νκ΅μ΄")
st.markdown("- μκ³ κΈ° λ³Άμλ°₯ λ μνΌ")
st.markdown("- μ μμ° μ€νμ΄μ€ λ μνΌ")
st.markdown("- λΉλ¨λ³μ μ’μ μμ νκ΅μ΄")
def eng_func():
st.title("Food and Nutrition Recommendation System")
st.write("Welcome to Food and Nutrition Recommendation System")
st.markdown('''The following are some examples that the webpage can help with :
- 200-calorie foods Korean
- recipe for beef fried rice
- rice shrimp spices recipe
- foods for diabetes Korean''')
# Streamlit app
def main():
target_language = "ko" # Set the target language to Korean
col1, col2 = st.columns(2)
with col1:
eng_func()
with col2:
korean_text()
prompt = st.text_area("Enter your request for food recommendation/ μμ μΆμ² μμ²μ μ
λ ₯νμΈμ ")
if st.button("Get Recommendation/μΆμ² λ°κΈ°"):
if prompt:
recommendation_prompt = f"I'm looking for a food recommendation with the complete ingredients list based on the following criteria: {prompt}"
recommendation = get_food_recommendation(recommendation_prompt)
translated_recommendation = translate_text(recommendation, target_language)
st.markdown("Recommendation (English / Korean):")
col3, col4 = st.columns(2)
with col3:
st.write(recommendation)
with col4:
st.write(translated_recommendation)
else:
st.warning("Please enter your request.")
if __name__ == "__main__":
main()
|