Update app.py
Browse files
app.py
CHANGED
@@ -835,21 +835,41 @@ def deploy_to_huggingface(code: str):
|
|
835 |
return "ํ์ฌ HuggingFace API ์์ฒญ์ด ์ ํ๋์์ต๋๋ค. ์ ์ ํ ๋ค์ ์๋ํด์ฃผ์ธ์."
|
836 |
raise e
|
837 |
|
838 |
-
# 6) ์ฝ๋ ์ ๋ฆฌ
|
839 |
code = code.replace("```python", "").replace("```", "").strip()
|
840 |
|
841 |
-
#
|
842 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
843 |
|
844 |
-
#
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
|
|
|
|
850 |
|
|
|
|
|
|
|
851 |
# 7) ์ ์ฒด ์ ํ๋ฆฌ์ผ์ด์
์ฝ๋ ์์ฑ
|
852 |
-
full_app_code =
|
853 |
|
854 |
# 8) ํ์ผ ์์ฑ ๋ฐ ์
๋ก๋
|
855 |
with open("app.py", "w", encoding="utf-8") as f:
|
@@ -863,7 +883,7 @@ def deploy_to_huggingface(code: str):
|
|
863 |
)
|
864 |
|
865 |
# requirements.txt ์์ฑ ๋ฐ ์
๋ก๋
|
866 |
-
requirements =
|
867 |
|
868 |
with open("requirements.txt", "w") as f:
|
869 |
f.write(requirements)
|
|
|
835 |
return "ํ์ฌ HuggingFace API ์์ฒญ์ด ์ ํ๋์์ต๋๋ค. ์ ์ ํ ๋ค์ ์๋ํด์ฃผ์ธ์."
|
836 |
raise e
|
837 |
|
838 |
+
# 6) ์ฝ๋ ์ ๋ฆฌ ๋ฐ import ๋ถ์
|
839 |
code = code.replace("```python", "").replace("```", "").strip()
|
840 |
|
841 |
+
# Import ๋ฌธ ์ถ์ถ ๋ฐ requirements.txt ์์ฑ์ ์ํ ๋งคํ
|
842 |
+
import_mapping = {
|
843 |
+
'gradio': 'gradio>=4.0.0',
|
844 |
+
'numpy': 'numpy',
|
845 |
+
'pandas': 'pandas',
|
846 |
+
'torch': 'torch',
|
847 |
+
'matplotlib': 'matplotlib',
|
848 |
+
'plotly': 'plotly',
|
849 |
+
'transformers': 'transformers',
|
850 |
+
'PIL': 'Pillow',
|
851 |
+
'cv2': 'opencv-python',
|
852 |
+
'sklearn': 'scikit-learn',
|
853 |
+
'tensorflow': 'tensorflow',
|
854 |
+
'scipy': 'scipy'
|
855 |
+
}
|
856 |
+
|
857 |
+
required_packages = set(['gradio>=4.0.0']) # gradio๋ ๊ธฐ๋ณธ์ผ๋ก ํฌํจ
|
858 |
|
859 |
+
# ์ฝ๋์์ import ๋ฌธ ๋ถ์
|
860 |
+
for line in code.split('\n'):
|
861 |
+
if line.startswith('import ') or line.startswith('from '):
|
862 |
+
# 'import' ๋๋ 'from' ๋ฌธ์์ ํจํค์ง ์ด๋ฆ ์ถ์ถ
|
863 |
+
if line.startswith('import '):
|
864 |
+
package = line.split('import ')[1].split()[0].split('.')[0]
|
865 |
+
else:
|
866 |
+
package = line.split('from ')[1].split()[0].split('.')[0]
|
867 |
|
868 |
+
if package in import_mapping:
|
869 |
+
required_packages.add(import_mapping[package])
|
870 |
+
|
871 |
# 7) ์ ์ฒด ์ ํ๋ฆฌ์ผ์ด์
์ฝ๋ ์์ฑ
|
872 |
+
full_app_code = code
|
873 |
|
874 |
# 8) ํ์ผ ์์ฑ ๋ฐ ์
๋ก๋
|
875 |
with open("app.py", "w", encoding="utf-8") as f:
|
|
|
883 |
)
|
884 |
|
885 |
# requirements.txt ์์ฑ ๋ฐ ์
๋ก๋
|
886 |
+
requirements = '\n'.join(sorted(required_packages))
|
887 |
|
888 |
with open("requirements.txt", "w") as f:
|
889 |
f.write(requirements)
|