File size: 2,644 Bytes
654e610
 
1d23fb8
654e610
 
 
1d23fb8
 
 
 
 
654e610
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d23fb8
 
 
 
 
 
 
 
 
 
 
654e610
96a3fc4
00ed128
35f9d15
6714000
 
 
00ed128
654e610
1d23fb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
654e610
 
 
1d23fb8
 
 
 
 
 
 
 
 
 
654e610
 
 
 
 
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()