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)
|