Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 =
|
| 37 |
-
|
| 38 |
-
self.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 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:
|