Calorie-Calculator / food_rec.py
shrut27's picture
Create food_rec.py
75ecec3
raw
history blame
2.64 kB
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()