immunobiotech commited on
Commit
71fcebb
ยท
verified ยท
1 Parent(s): e23f42b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -57,10 +57,10 @@ for split in korean_food_dataset.keys():
57
 
58
  def find_related_restaurants(query: str, limit: int = 3) -> list:
59
  """
60
- Query์— ๊ด€๋ จ๋œ ๋ฏธ์‰๋ฆฐ ๋ ˆ์Šคํ† ๋ž‘์„ find.csv์—์„œ ์ฐพ์•„ ๋ฐ˜ํ™˜
61
  """
62
  try:
63
- with open('find.csv', 'r', encoding='utf-8') as f:
64
  reader = csv.DictReader(f)
65
  restaurants = list(reader)
66
 
@@ -75,6 +75,9 @@ def find_related_restaurants(query: str, limit: int = 3) -> list:
75
  break
76
 
77
  return related
 
 
 
78
  except Exception as e:
79
  print(f"Error finding restaurants: {e}")
80
  return []
@@ -757,7 +760,7 @@ with gr.Blocks(
757
  queue=False
758
  )
759
 
760
- # 4) ๋ฏธ์‰๋ฆฐ ๋ ˆ์Šคํ† ๋ž‘ ํƒญ
761
  with gr.TabItem("MICHELIN Restaurant", id="restaurant_tab"):
762
  with gr.Row():
763
  search_box = gr.Textbox(
@@ -767,13 +770,13 @@ with gr.Blocks(
767
  )
768
  cuisine_dropdown = gr.Dropdown(
769
  label="์š”๋ฆฌ ์ข…๋ฅ˜",
770
- choices=["์ „์ฒด"], # find.csv ํŒŒ์ผ ์กด์žฌ ์‹œ ๋™์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ
771
  value="์ „์ฒด",
772
  scale=1
773
  )
774
  award_dropdown = gr.Dropdown(
775
  label="๋ฏธ์‰๋ฆฐ ๋“ฑ๊ธ‰",
776
- choices=["์ „์ฒด"], # find.csv ํŒŒ์ผ ์กด์žฌ ์‹œ ๋™์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ
777
  value="์ „์ฒด",
778
  scale=1
779
  )
@@ -788,25 +791,27 @@ with gr.Blocks(
788
 
789
  def init_dropdowns():
790
  try:
791
- with open('find.csv', 'r', encoding='utf-8') as f:
792
  reader = csv.DictReader(f)
793
  restaurants = list(reader)
794
- cuisines = ["์ „์ฒด"] + sorted(set(r['Cuisine'] for r in restaurants if r['Cuisine']))
795
- awards = ["์ „์ฒด"] + sorted(set(r['Award'] for r in restaurants if r['Award']))
 
 
796
  return cuisines, awards
797
  except FileNotFoundError:
798
- print("Warning: find.csv file not found")
799
- return ["์ „์ฒด"], ["์ „์ฒด"]
800
-
801
  def search_restaurants(search_term, cuisine, award):
802
  try:
803
- with open('find.csv', 'r', encoding='utf-8') as f:
804
  reader = csv.DictReader(f)
805
  restaurants = list(reader)
806
-
807
  filtered = []
808
  search_term = search_term.lower() if search_term else ""
809
-
810
  for r in restaurants:
811
  if search_term == "" or \
812
  search_term in r['Name'].lower() or \
@@ -821,16 +826,16 @@ with gr.Blocks(
821
  ])
822
  if len(filtered) >= 10: # ์ตœ๋Œ€ 10๊ฐœ ๊ฒฐ๊ณผ๋กœ ์ œํ•œ
823
  break
824
-
825
  return filtered
826
  except FileNotFoundError:
827
- return [["ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค", "", "", "", "", "", "find.csv ํŒŒ์ผ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”"]]
828
 
829
- # ๋“œ๋กญ๋‹ค์šด ์ดˆ๊ธฐํ™”
830
  cuisines, awards = init_dropdowns()
831
  cuisine_dropdown.choices = cuisines
832
  award_dropdown.choices = awards
833
-
834
  search_button.click(
835
  search_restaurants,
836
  inputs=[search_box, cuisine_dropdown, award_dropdown],
@@ -839,6 +844,7 @@ with gr.Blocks(
839
 
840
 
841
 
 
842
  # ์‚ฌ์šฉ ๊ฐ€์ด๋“œ ํƒญ
843
  with gr.TabItem("์ด์šฉ ๋ฐฉ๋ฒ•", id="instructions_tab"):
844
  gr.Markdown(
 
57
 
58
  def find_related_restaurants(query: str, limit: int = 3) -> list:
59
  """
60
+ Query์— ๊ด€๋ จ๋œ ๋ฏธ์‰๋ฆฐ ๋ ˆ์Šคํ† ๋ž‘์„ michelin_my_maps.csv์—์„œ ์ฐพ์•„ ๋ฐ˜ํ™˜
61
  """
62
  try:
63
+ with open('michelin_my_maps.csv', 'r', encoding='utf-8') as f:
64
  reader = csv.DictReader(f)
65
  restaurants = list(reader)
66
 
 
75
  break
76
 
77
  return related
78
+ except FileNotFoundError:
79
+ print("Warning: michelin_my_maps.csv file not found")
80
+ return []
81
  except Exception as e:
82
  print(f"Error finding restaurants: {e}")
83
  return []
 
760
  queue=False
761
  )
762
 
763
+ # 4) ๋ฏธ์‰๋ฆฐ ๋ ˆ์Šคํ† ๋ž‘ ํƒญ
764
  with gr.TabItem("MICHELIN Restaurant", id="restaurant_tab"):
765
  with gr.Row():
766
  search_box = gr.Textbox(
 
770
  )
771
  cuisine_dropdown = gr.Dropdown(
772
  label="์š”๋ฆฌ ์ข…๋ฅ˜",
773
+ choices=[("์ „์ฒด", "์ „์ฒด")], # ์ดˆ๊ธฐ๊ฐ’ ์„ค์ •
774
  value="์ „์ฒด",
775
  scale=1
776
  )
777
  award_dropdown = gr.Dropdown(
778
  label="๋ฏธ์‰๋ฆฐ ๋“ฑ๊ธ‰",
779
+ choices=[("์ „์ฒด", "์ „์ฒด")], # ์ดˆ๊ธฐ๊ฐ’ ์„ค์ •
780
  value="์ „์ฒด",
781
  scale=1
782
  )
 
791
 
792
  def init_dropdowns():
793
  try:
794
+ with open('michelin_my_maps.csv', 'r', encoding='utf-8') as f:
795
  reader = csv.DictReader(f)
796
  restaurants = list(reader)
797
+ cuisines = [("์ „์ฒด", "์ „์ฒด")] + [(cuisine, cuisine) for cuisine in
798
+ sorted(set(r['Cuisine'] for r in restaurants if r['Cuisine']))]
799
+ awards = [("์ „์ฒด", "์ „์ฒด")] + [(award, award) for award in
800
+ sorted(set(r['Award'] for r in restaurants if r['Award']))]
801
  return cuisines, awards
802
  except FileNotFoundError:
803
+ print("Warning: michelin_my_maps.csv file not found")
804
+ return [("์ „์ฒด", "์ „์ฒด")], [("์ „์ฒด", "์ „์ฒด")]
805
+
806
  def search_restaurants(search_term, cuisine, award):
807
  try:
808
+ with open('michelin_my_maps.csv', 'r', encoding='utf-8') as f:
809
  reader = csv.DictReader(f)
810
  restaurants = list(reader)
811
+
812
  filtered = []
813
  search_term = search_term.lower() if search_term else ""
814
+
815
  for r in restaurants:
816
  if search_term == "" or \
817
  search_term in r['Name'].lower() or \
 
826
  ])
827
  if len(filtered) >= 10: # ์ตœ๋Œ€ 10๊ฐœ ๊ฒฐ๊ณผ๋กœ ์ œํ•œ
828
  break
829
+
830
  return filtered
831
  except FileNotFoundError:
832
+ return [["ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค", "", "", "", "", "", "michelin_my_maps.csv ํŒŒ์ผ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”"]]
833
 
834
+ # ๋“œ๋กญ๋‹ค์šด ์ดˆ๊ธฐํ™”
835
  cuisines, awards = init_dropdowns()
836
  cuisine_dropdown.choices = cuisines
837
  award_dropdown.choices = awards
838
+
839
  search_button.click(
840
  search_restaurants,
841
  inputs=[search_box, cuisine_dropdown, award_dropdown],
 
844
 
845
 
846
 
847
+
848
  # ์‚ฌ์šฉ ๊ฐ€์ด๋“œ ํƒญ
849
  with gr.TabItem("์ด์šฉ ๋ฐฉ๋ฒ•", id="instructions_tab"):
850
  gr.Markdown(