seawolf2357 commited on
Commit
c46c8e9
ยท
verified ยท
1 Parent(s): b6e2ee7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -940,7 +940,7 @@ def deploy_to_huggingface(code: str):
940
  }
941
 
942
  required_packages = set(['gradio==5.5.0']) # gradio๋Š” ๊ธฐ๋ณธ์œผ๋กœ ํฌํ•จ
943
-
944
  # ์ฝ”๋“œ์—์„œ import ๋ฌธ ๋ถ„์„
945
  import_pattern = r'^(?:from\s+(\S+)|import\s+([^,\s]+)(?:\s*,\s*([^,\s]+))*)'
946
 
@@ -949,9 +949,9 @@ def deploy_to_huggingface(code: str):
949
  if line.startswith('import ') or line.startswith('from '):
950
  matches = re.match(import_pattern, line)
951
  if matches:
952
- if matches.group(1): # from ... import ...
953
  package = matches.group(1).split('.')[0]
954
- else: # import ...
955
  packages = [p.strip() for p in re.findall(r'[\w.]+', line[7:])]
956
  for package in packages:
957
  package = package.split('.')[0]
@@ -959,8 +959,12 @@ def deploy_to_huggingface(code: str):
959
  required_packages.add(import_mapping[package])
960
 
961
  # 7) ์ „์ฒด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฝ”๋“œ ์ƒ์„ฑ
962
- full_app_code = code
963
-
 
 
 
 
964
  # 8) ํŒŒ์ผ ์ƒ์„ฑ ๋ฐ ์—…๋กœ๋“œ
965
  with open("app.py", "w", encoding="utf-8") as f:
966
  f.write(full_app_code)
@@ -985,6 +989,8 @@ def deploy_to_huggingface(code: str):
985
  repo_type="space"
986
  )
987
 
 
 
988
  # 9) Rate Limit ์ •๋ณด ์—…๋ฐ์ดํŠธ
989
  deploy_count += 1
990
  with open(rate_limit_file, 'w') as f:
 
940
  }
941
 
942
  required_packages = set(['gradio==5.5.0']) # gradio๋Š” ๊ธฐ๋ณธ์œผ๋กœ ํฌํ•จ
943
+
944
  # ์ฝ”๋“œ์—์„œ import ๋ฌธ ๋ถ„์„
945
  import_pattern = r'^(?:from\s+(\S+)|import\s+([^,\s]+)(?:\s*,\s*([^,\s]+))*)'
946
 
 
949
  if line.startswith('import ') or line.startswith('from '):
950
  matches = re.match(import_pattern, line)
951
  if matches:
952
+ if matches.group(1):
953
  package = matches.group(1).split('.')[0]
954
+ else:
955
  packages = [p.strip() for p in re.findall(r'[\w.]+', line[7:])]
956
  for package in packages:
957
  package = package.split('.')[0]
 
959
  required_packages.add(import_mapping[package])
960
 
961
  # 7) ์ „์ฒด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฝ”๋“œ ์ƒ์„ฑ
962
+ # demo.launch() ํ˜ธ์ถœ์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์—†์œผ๋ฉด ์ถ”๊ฐ€
963
+ if "demo.launch()" not in code:
964
+ full_app_code = code + "\n\nif __name__ == '__main__':\n demo.launch()"
965
+ else:
966
+ full_app_code = code
967
+
968
  # 8) ํŒŒ์ผ ์ƒ์„ฑ ๋ฐ ์—…๋กœ๋“œ
969
  with open("app.py", "w", encoding="utf-8") as f:
970
  f.write(full_app_code)
 
989
  repo_type="space"
990
  )
991
 
992
+
993
+
994
  # 9) Rate Limit ์ •๋ณด ์—…๋ฐ์ดํŠธ
995
  deploy_count += 1
996
  with open(rate_limit_file, 'w') as f: