Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,21 +17,50 @@ def test():
|
|
17 |
def process():
|
18 |
import subprocess
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
# Gantilah "app.py" dengan nama berkas aplikasi Python Anda
|
21 |
-
pip_script = "install -r requirements.txt"
|
22 |
# batch_file_path = "./.run.bat"
|
23 |
python_script = "entry_with_update.py"
|
24 |
|
25 |
# Argument yang ingin Anda tambahkan
|
26 |
-
additional_arguments = ["--in-browser", "--all-in-fp32", "--directml", "--debug-mode", "--attention-
|
27 |
|
28 |
# Gabungkan semua argumen
|
29 |
-
PIP = ["pip",
|
30 |
command = ["python", python_script] + additional_arguments
|
31 |
|
32 |
# Jalankan skrip menggunakan subprocess
|
33 |
-
|
34 |
subprocess.run(command)# Menjalankan file batch
|
|
|
|
|
35 |
print(command)
|
36 |
# subprocess.run([batch_file_path], shell=True)
|
37 |
|
|
|
17 |
def process():
|
18 |
import subprocess
|
19 |
|
20 |
+
def uninstall_and_install_gradio(version):
|
21 |
+
# Uninstall current Gradio
|
22 |
+
uninstall_command = ["pip", "uninstall", "gradio", "-y"]
|
23 |
+
subprocess.run(uninstall_command)
|
24 |
+
|
25 |
+
# Install specific version of Gradio
|
26 |
+
install_command = ["pip", "install", f"gradio=={version}"]
|
27 |
+
subprocess.run(install_command)
|
28 |
+
|
29 |
+
# Gantilah "3.41.2" dengan versi Gradio yang diinginkan
|
30 |
+
desired_version = "3.41.2"
|
31 |
+
|
32 |
+
# Periksa versi Gradio yang terinstal
|
33 |
+
current_version_command = ["pip", "show", "gradio"]
|
34 |
+
result = subprocess.run(current_version_command, capture_output=True, text=True)
|
35 |
+
current_version = None
|
36 |
+
|
37 |
+
if "Version" in result.stdout:
|
38 |
+
current_version = result.stdout.split("Version:")[1].strip()
|
39 |
+
|
40 |
+
# Cek dan lakukan uninstall dan install jika versi tidak sesuai
|
41 |
+
if current_version != desired_version:
|
42 |
+
uninstall_and_install_gradio(desired_version)
|
43 |
+
print(f"Gradio has been updated to version {desired_version}")
|
44 |
+
else:
|
45 |
+
print(f"Gradio is already at version {desired_version}")
|
46 |
+
|
47 |
# Gantilah "app.py" dengan nama berkas aplikasi Python Anda
|
48 |
+
# pip_script = "install -r requirements.txt"
|
49 |
# batch_file_path = "./.run.bat"
|
50 |
python_script = "entry_with_update.py"
|
51 |
|
52 |
# Argument yang ingin Anda tambahkan
|
53 |
+
additional_arguments = ["--in-browser", "--all-in-fp32", "--directml", "--debug-mode", "--attention-split", "--multi-user", "--always-cpu", "--is-windows-embedded-python"]
|
54 |
|
55 |
# Gabungkan semua argumen
|
56 |
+
PIP = ["pip", " install", "-r", "requirements.txt"]
|
57 |
command = ["python", python_script] + additional_arguments
|
58 |
|
59 |
# Jalankan skrip menggunakan subprocess
|
60 |
+
subprocess.run(PIP)
|
61 |
subprocess.run(command)# Menjalankan file batch
|
62 |
+
|
63 |
+
print(PIP)
|
64 |
print(command)
|
65 |
# subprocess.run([batch_file_path], shell=True)
|
66 |
|