npc0 commited on
Commit
edf0e69
·
1 Parent(s): 1fde593

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -22,7 +22,7 @@ class GUI:
22
  inp.change(self.process, inp, out)
23
  self.ws = None
24
  self.out = []
25
- demo.launch()
26
 
27
  def process(self, file, profile: gr.OAuthProfile | None):
28
  if profile is None:
@@ -32,20 +32,22 @@ class GUI:
32
  chapter_titles = epub2txt.content_titles
33
  title = epub2txt.title
34
  if self.ws is None:
35
- self.ws = create_connection(f"ws://localhost/{file.name}/ws")
36
- res = self.ws.recv()
37
- if 'chsum: ' in res:
38
- self.out.append(res.remove("chsum: "))
39
- elif 'draft_sum: ' in res:
40
- h = res[11:]
41
- elif 'output: ' in res:
42
- self.ws.close()
43
- self.ws = None
44
- self.out = []
45
- return gr.update(value=res)
46
- return gr.update(
47
- value=f"# {title}\n\n" +h+ "\n\n".join(
48
- [f"## {ct}\n\n{c}" for ct, c in zip(chapter_titles, self.out)]))
 
 
49
 
50
  def hello(self, profile: gr.OAuthProfile | None):
51
  if profile is None:
 
22
  inp.change(self.process, inp, out)
23
  self.ws = None
24
  self.out = []
25
+ demo.queue(concurrency_count=2).launch()
26
 
27
  def process(self, file, profile: gr.OAuthProfile | None):
28
  if profile is None:
 
32
  chapter_titles = epub2txt.content_titles
33
  title = epub2txt.title
34
  if self.ws is None:
35
+ self.ws = create_connection(f"ws://localhost:8000/{file.name}/ws")
36
+ res = ''
37
+ while 'output: ' not in res:
38
+ res = self.ws.recv()
39
+ if 'chsum: ' in res:
40
+ self.out.append(res.remove("chsum: "))
41
+ elif 'draft_sum: ' in res:
42
+ h = res[11:]
43
+ elif 'output: ' in res:
44
+ self.ws.close()
45
+ self.ws = None
46
+ self.out = []
47
+ yield gr.update(value=res)
48
+ yield gr.update(
49
+ value=f"# {title}\n\n" +h+ "\n\n".join(
50
+ [f"## {ct}\n\n{c}" for ct, c in zip(chapter_titles, self.out)]))
51
 
52
  def hello(self, profile: gr.OAuthProfile | None):
53
  if profile is None: