jonigata commited on
Commit
0700b92
1 Parent(s): f163aba

fix json import

Browse files
Files changed (3) hide show
  1. fileservice.py +2 -8
  2. js/poseMaker.js +3 -0
  3. main.py +3 -1
fileservice.py CHANGED
@@ -1,7 +1,7 @@
1
  from fastapi import FastAPI, Request, Response
2
 
3
  filenames = ["js/poseMaker.js"]
4
- contents = '\n'.join([open(x).read() for x in filenames])
5
 
6
  app = FastAPI()
7
 
@@ -15,13 +15,7 @@ async def insert_js(request: Request, call_next):
15
  async for chunk in response.body_iterator:
16
  response_body += chunk.decode()
17
 
18
- some_javascript = f"""
19
- <script type="text/javascript" defer>
20
- {contents}
21
- </script>
22
- """
23
-
24
- response_body = response_body.replace("</body>", some_javascript + "</body>")
25
 
26
  del response.headers["content-length"]
27
 
 
1
  from fastapi import FastAPI, Request, Response
2
 
3
  filenames = ["js/poseMaker.js"]
4
+ contents = '\n'.join([f"<script type='text/javascript' src='{x}'></script>" for x in filenames])
5
 
6
  app = FastAPI()
7
 
 
15
  async for chunk in response.body_iterator:
16
  response_body += chunk.decode()
17
 
18
+ response_body = response_body.replace("</body>", contents + "</body>")
 
 
 
 
 
 
19
 
20
  del response.headers["content-length"]
21
 
js/poseMaker.js CHANGED
@@ -623,6 +623,9 @@ function initializeEditor() {
623
 
624
  function importPose(jsonData) {
625
  if (jsonData != null) {
 
 
 
626
  newPoseData = makePoseDataFromCandidateAndSubset(jsonData.candidate, jsonData.subset);
627
  } else {
628
  newPoseData = makePoseDataFromCandidateAndSubset(sampleCandidateSource, [sampleSubsetElementSource]);
 
623
 
624
  function importPose(jsonData) {
625
  if (jsonData != null) {
626
+ if (Array.isArray(jsonData)) {
627
+ jsonData = jsonData[0]; // 自分で仕込んだバグ回避
628
+ }
629
  newPoseData = makePoseDataFromCandidateAndSubset(jsonData.candidate, jsonData.subset);
630
  } else {
631
  newPoseData = makePoseDataFromCandidateAndSubset(sampleCandidateSource, [sampleSubsetElementSource]);
main.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import json as js
3
  import util
 
4
  from fileservice import app
5
  from pose import infer, draw
6
 
@@ -142,7 +143,7 @@ When using Q, X, C, R, pressing and dont release until the operation is complete
142
  saveBtn.click(
143
  fn = None,
144
  inputs = [], outputs = [json],
145
- _js="() => { return [savePose()]; }")
146
  jsonSource.change(
147
  fn = lambda x: x,
148
  inputs = [jsonSource], outputs = [json])
@@ -159,4 +160,5 @@ When using Q, X, C, R, pressing and dont release until the operation is complete
159
  demo.load(fn=None, inputs=[], outputs=[], _js="() => { initializeEditor(); importPose(); return []; }")
160
 
161
  print("mount")
 
162
  gr.mount_gradio_app(app, demo, path="/")
 
1
  import gradio as gr
2
  import json as js
3
  import util
4
+ from fastapi.staticfiles import StaticFiles
5
  from fileservice import app
6
  from pose import infer, draw
7
 
 
143
  saveBtn.click(
144
  fn = None,
145
  inputs = [], outputs = [json],
146
+ _js="() => { return savePose(); }")
147
  jsonSource.change(
148
  fn = lambda x: x,
149
  inputs = [jsonSource], outputs = [json])
 
160
  demo.load(fn=None, inputs=[], outputs=[], _js="() => { initializeEditor(); importPose(); return []; }")
161
 
162
  print("mount")
163
+ app.mount("/js", StaticFiles(directory="js"), name="js")
164
  gr.mount_gradio_app(app, demo, path="/")