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()