Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import uuid
|
|
| 4 |
import gradio as gr
|
| 5 |
from pathlib import Path
|
| 6 |
from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
|
|
|
|
| 7 |
|
| 8 |
#token_self = os.environ['HF_TOKEN']
|
| 9 |
o=os.environ['P']
|
|
@@ -66,18 +67,50 @@ def build_space(token,t_name,s_type,m_type):
|
|
| 66 |
app = f.read()
|
| 67 |
app = app.replace("$name2", m_type)
|
| 68 |
|
| 69 |
-
with open("at.py", "w") as f:
|
| 70 |
f.write(app)
|
| 71 |
|
| 72 |
api.upload_file(
|
| 73 |
-
path_or_fileobj="at.py",
|
| 74 |
path_in_repo="app.py",
|
| 75 |
repo_id=repo_name,
|
| 76 |
token=token,
|
| 77 |
repo_type="space",
|
| 78 |
)
|
| 79 |
-
os.remove("at.py")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
return gr.HTML.update(f'''<center>Link to space <a href="https://huggingface.co/spaces/{repo_name}" target="_blank">https://huggingface.co/spaces/{repo_name}</a><center><br>''')
|
| 82 |
except Exception as e:
|
| 83 |
return gr.HTML.update(f"""{str(e)}""")
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from pathlib import Path
|
| 6 |
from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
|
| 7 |
+
uid = uuid.uuid4()
|
| 8 |
|
| 9 |
#token_self = os.environ['HF_TOKEN']
|
| 10 |
o=os.environ['P']
|
|
|
|
| 67 |
app = f.read()
|
| 68 |
app = app.replace("$name2", m_type)
|
| 69 |
|
| 70 |
+
with open(f"{uid}at.py", "w") as f:
|
| 71 |
f.write(app)
|
| 72 |
|
| 73 |
api.upload_file(
|
| 74 |
+
path_or_fileobj=f"{uid}at.py",
|
| 75 |
path_in_repo="app.py",
|
| 76 |
repo_id=repo_name,
|
| 77 |
token=token,
|
| 78 |
repo_type="space",
|
| 79 |
)
|
| 80 |
+
os.remove(f"{uid}at.py")
|
| 81 |
+
elif s_type == "B":
|
| 82 |
+
with open("b.py", "r") as f:
|
| 83 |
+
app = f.read()
|
| 84 |
+
app = app.replace("$name2", m_type)
|
| 85 |
+
|
| 86 |
+
with open(f"{uid}bt.py", "w") as f:
|
| 87 |
+
f.write(app)
|
| 88 |
|
| 89 |
+
api.upload_file(
|
| 90 |
+
path_or_fileobj=f"{uid}bt.py",
|
| 91 |
+
path_in_repo="app.py",
|
| 92 |
+
repo_id=repo_name,
|
| 93 |
+
token=token,
|
| 94 |
+
repo_type="space",
|
| 95 |
+
)
|
| 96 |
+
os.remove(f"{uid}bt.py")
|
| 97 |
+
elif s_type == "C":
|
| 98 |
+
with open("c.py", "r") as f:
|
| 99 |
+
app = f.read()
|
| 100 |
+
app = app.replace("$name2", m_type)
|
| 101 |
+
|
| 102 |
+
with open(f"{uid}ct.py", "w") as f:
|
| 103 |
+
f.write(app)
|
| 104 |
+
|
| 105 |
+
api.upload_file(
|
| 106 |
+
path_or_fileobj=f"{uid}ct.py",
|
| 107 |
+
path_in_repo="app.py",
|
| 108 |
+
repo_id=repo_name,
|
| 109 |
+
token=token,
|
| 110 |
+
repo_type="space",
|
| 111 |
+
)
|
| 112 |
+
os.remove(f"{uid}ct.py")
|
| 113 |
+
|
| 114 |
return gr.HTML.update(f'''<center>Link to space <a href="https://huggingface.co/spaces/{repo_name}" target="_blank">https://huggingface.co/spaces/{repo_name}</a><center><br>''')
|
| 115 |
except Exception as e:
|
| 116 |
return gr.HTML.update(f"""{str(e)}""")
|