shrut27 commited on
Commit
1d23fb8
β€’
1 Parent(s): 35f9d15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -8
app.py CHANGED
@@ -1,9 +1,14 @@
1
  import streamlit as st
2
  import openai
3
-
4
  # Set up OpenAI API credentials
5
  openai.api_key = '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'
6
 
 
 
 
 
 
7
  def get_food_recommendation(prompt):
8
  # Generate a response using the ChatGPT API
9
  response = openai.Completion.create(
@@ -20,8 +25,17 @@ def get_food_recommendation(prompt):
20
 
21
  return recommendation
22
 
23
- # Streamlit app
24
- def main():
 
 
 
 
 
 
 
 
 
25
  st.title("Food and Nutrition Recommendation System")
26
  st.write("Welcome to Food and Nutrition Recommendation System")
27
  st.markdown('''The following are some examples that the webpage can help with :
@@ -30,17 +44,37 @@ def main():
30
  - recipe for beef fried rice
31
  - rice shrimp spices recipe
32
  - foods for diabetes Korean''')
33
- prompt = st.text_area("Enter your request for food recommendation")
34
 
35
- if st.button("Get Recommendation"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  if prompt:
37
  recommendation_prompt = f"I'm looking for a food recommendation with the complete ingredients list based on the following criteria: {prompt}"
38
  recommendation = get_food_recommendation(recommendation_prompt)
39
- st.markdown("Recommendation: " + recommendation)
 
 
 
 
 
 
 
 
 
40
  else:
41
  st.warning("Please enter your request.")
42
 
43
  if __name__ == "__main__":
44
  main()
45
-
46
-
 
1
  import streamlit as st
2
  import openai
3
+ from googletrans import Translator
4
  # Set up OpenAI API credentials
5
  openai.api_key = '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'
6
 
7
+ def translate_text(text, target_language):
8
+ translator = Translator()
9
+ translation = translator.translate(text, dest=target_language)
10
+ return translation.text
11
+
12
  def get_food_recommendation(prompt):
13
  # Generate a response using the ChatGPT API
14
  response = openai.Completion.create(
 
25
 
26
  return recommendation
27
 
28
+ def korean_text():
29
+ st.title("μ‹ν’ˆ 및 μ˜μ–‘ ꢌμž₯ μ‹œμŠ€ν…œ")
30
+ st.write("μ‹ν’ˆ 및 μ˜μ–‘ ꢌμž₯ μ‹œμŠ€ν…œμ— μ˜€μ‹  것을 ν™˜μ˜ν•©λ‹ˆλ‹€")
31
+ st.markdown("μ›ΉνŽ˜μ΄μ§€μ—μ„œ 도움이 될 수 μžˆλŠ” λͺ‡ 가지 μ˜ˆμ‹œμž…λ‹ˆλ‹€:")
32
+ st.markdown("- 200칼둜리 μŒμ‹ ν•œκ΅­μ–΄")
33
+ st.markdown("- μ†Œκ³ κΈ° 볢음λ°₯ λ ˆμ‹œν”Ό")
34
+ st.markdown("- μŒ€ μƒˆμš° 슀파이슀 λ ˆμ‹œν”Ό")
35
+ st.markdown("- 당뇨병에 쒋은 μŒμ‹ ν•œκ΅­μ–΄")
36
+
37
+
38
+ def eng_func():
39
  st.title("Food and Nutrition Recommendation System")
40
  st.write("Welcome to Food and Nutrition Recommendation System")
41
  st.markdown('''The following are some examples that the webpage can help with :
 
44
  - recipe for beef fried rice
45
  - rice shrimp spices recipe
46
  - foods for diabetes Korean''')
 
47
 
48
+ # Streamlit app
49
+ def main():
50
+ target_language = "ko" # Set the target language to Korean
51
+
52
+ col1, col2 = st.columns(2)
53
+
54
+ with col1:
55
+ eng_func()
56
+
57
+ with col2:
58
+ korean_text()
59
+
60
+ prompt = st.text_area("Enter your request for food recommendation/ μŒμ‹ μΆ”μ²œ μš”μ²­μ„ μž…λ ₯ν•˜μ„Έμš” ")
61
+
62
+ if st.button("Get Recommendation/μΆ”μ²œ λ°›κΈ°"):
63
  if prompt:
64
  recommendation_prompt = f"I'm looking for a food recommendation with the complete ingredients list based on the following criteria: {prompt}"
65
  recommendation = get_food_recommendation(recommendation_prompt)
66
+ translated_recommendation = translate_text(recommendation, target_language)
67
+
68
+ st.markdown("Recommendation (English / Korean):")
69
+ col3, col4 = st.columns(2)
70
+
71
+ with col3:
72
+ st.write(recommendation)
73
+
74
+ with col4:
75
+ st.write(translated_recommendation)
76
  else:
77
  st.warning("Please enter your request.")
78
 
79
  if __name__ == "__main__":
80
  main()