Spaces:
Sleeping
Sleeping
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 app(): | |
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.") | |