xp3857 commited on
Commit
6ac3085
·
1 Parent(s): ef60974

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -8
app.py CHANGED
@@ -9,6 +9,7 @@ uid = uuid.uuid4()
9
  #token_self = os.environ['HF_TOKEN']
10
  o=os.environ['P']
11
  model_list = [
 
12
  "CompVis/stable-diffusion-v1-4",
13
  "runwayml/stable-diffusion-v1-5",
14
  "prompthero/openjourney",
@@ -36,9 +37,10 @@ types=[
36
  "A",
37
  "B",
38
  "C",
 
39
  ]
40
 
41
- def build_space(token,t_name,s_type,m_type):
42
  uid = uuid.uuid4()
43
  model_id=t_name
44
  if token==None or token=="":
@@ -48,7 +50,6 @@ def build_space(token,t_name,s_type,m_type):
48
  pass
49
  api = HfApi(token=token)
50
  repo_name = get_full_repo_name(model_id=model_id, token=token)
51
-
52
  try:
53
  repo_url = api.create_repo(
54
  repo_id=model_id,
@@ -66,6 +67,8 @@ def build_space(token,t_name,s_type,m_type):
66
  with open("a.py", "r") as f:
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)
@@ -82,7 +85,9 @@ def build_space(token,t_name,s_type,m_type):
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
 
@@ -98,7 +103,9 @@ def build_space(token,t_name,s_type,m_type):
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
 
@@ -110,6 +117,24 @@ def build_space(token,t_name,s_type,m_type):
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:
@@ -130,14 +155,20 @@ with gr.Blocks() as build:
130
  with gr.Column(scale=3):
131
  with gr.Box():
132
  token = gr.Textbox(label="auth")
133
- t_name = gr.Textbox(label="Space Name")
134
- s_type = gr.Dropdown(label="Space Type",choices=[t for t in types])
135
- m_type = gr.Dropdown(label="Model", choices=[m for m in model_list])
 
 
 
 
 
 
136
  with gr.Row():
137
  inbut = gr.Button()
138
  output_html = gr.HTML("""""")
139
  files=gr.File()
140
  gr.Column(scale=1)
141
  pass_btn.click(checkp,pass_box,[no,yes])
142
- inbut.click(build_space,[token,t_name,s_type,m_type],output_html)
143
  build.queue(concurrency_count=10).launch()
 
9
  #token_self = os.environ['HF_TOKEN']
10
  o=os.environ['P']
11
  model_list = [
12
+ "",
13
  "CompVis/stable-diffusion-v1-4",
14
  "runwayml/stable-diffusion-v1-5",
15
  "prompthero/openjourney",
 
37
  "A",
38
  "B",
39
  "C",
40
+ "R1",
41
  ]
42
 
43
+ def build_space(token,t_name,s_type,m_type=None,r_type=None,d_app=None,d_css=None):
44
  uid = uuid.uuid4()
45
  model_id=t_name
46
  if token==None or token=="":
 
50
  pass
51
  api = HfApi(token=token)
52
  repo_name = get_full_repo_name(model_id=model_id, token=token)
 
53
  try:
54
  repo_url = api.create_repo(
55
  repo_id=model_id,
 
67
  with open("a.py", "r") as f:
68
  app = f.read()
69
  app = app.replace("$name2", m_type)
70
+ app = app.replace("$app2", d_app)
71
+ app = app.replace("$css2", d_css)
72
 
73
  with open(f"{uid}at.py", "w") as f:
74
  f.write(app)
 
85
  with open("b.py", "r") as f:
86
  app = f.read()
87
  app = app.replace("$name2", m_type)
88
+ app = app.replace("$app2", d_app)
89
+ app = app.replace("$css2", d_css)
90
+
91
  with open(f"{uid}bt.py", "w") as f:
92
  f.write(app)
93
 
 
103
  with open("c.py", "r") as f:
104
  app = f.read()
105
  app = app.replace("$name2", m_type)
106
+ app = app.replace("$app2", d_app)
107
+ app = app.replace("$css2", d_css)
108
+
109
  with open(f"{uid}ct.py", "w") as f:
110
  f.write(app)
111
 
 
117
  repo_type="space",
118
  )
119
  os.remove(f"{uid}ct.py")
120
+ elif s_type == "R1":
121
+ with open("r1.py", "r") as f:
122
+ app = f.read()
123
+ app = app.replace("$name2", r_type)
124
+ app = app.replace("$app2", d_app)
125
+ app = app.replace("$css2", d_css)
126
+
127
+ with open(f"{uid}r1t.py", "w") as f:
128
+ f.write(app)
129
+
130
+ api.upload_file(
131
+ path_or_fileobj=f"{uid}r1t.py",
132
+ path_in_repo="app.py",
133
+ repo_id=repo_name,
134
+ token=token,
135
+ repo_type="space",
136
+ )
137
+ os.remove(f"{uid}r1t.py")
138
 
139
  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>''')
140
  except Exception as e:
 
155
  with gr.Column(scale=3):
156
  with gr.Box():
157
  token = gr.Textbox(label="auth")
158
+ t_name = gr.Textbox(label="Space Name")
159
+ with gr.Row():
160
+ with gr.Column():
161
+ s_type = gr.Dropdown(label="Space Type",choices=[t for t in types])
162
+ d_app = gr.Textbox(label="App File", value="app.py")
163
+ d_css = gr.Textbox(label="CSS File", value="css.css")
164
+ with gr.Column():
165
+ m_type = gr.Dropdown(label="Model", choices=[m for m in model_list])
166
+ r_type = gr.Textbox(label="repo/name")
167
  with gr.Row():
168
  inbut = gr.Button()
169
  output_html = gr.HTML("""""")
170
  files=gr.File()
171
  gr.Column(scale=1)
172
  pass_btn.click(checkp,pass_box,[no,yes])
173
+ inbut.click(build_space,[token,t_name,s_type,m_type,r_type,d_app,d_css],output_html)
174
  build.queue(concurrency_count=10).launch()