Spaces:
Runtime error
Runtime error
start and call ws api
Browse files
app.py
CHANGED
@@ -2,18 +2,13 @@ import os
|
|
2 |
import pip
|
3 |
import gradio as gr
|
4 |
from epub2txt import epub2txt
|
|
|
5 |
|
6 |
-
if not os.path.exists(
|
7 |
os.system("git clone --recurse-submodules https://github.com/ztxz16/fastllm.git")
|
8 |
-
os.system("cd fastllm; mkdir build; cd build; cmake ..; make -j")
|
9 |
-
# os.system("cd fastllm; mkdir build; cd build; cmake ..; make -j; cd tools; python setup.py install --user --prefix=")
|
10 |
# os.system("wget https://huggingface.co/huangyuyang/chatglm2-6b-int4.flm/resolve/main/chatglm2-6b-int4.flm")
|
11 |
-
|
12 |
-
# exit()
|
13 |
-
|
14 |
-
from fastllm_pytools import llm
|
15 |
-
model = llm.model("./chatglm2-6b-int4.flm")
|
16 |
-
prompt = os.getenv("prompt")
|
17 |
|
18 |
class GUI:
|
19 |
def __init__(self, *args, **kwargs):
|
@@ -22,21 +17,35 @@ class GUI:
|
|
22 |
gr.Markdown(scale=2).attach_load_event(self.hello, None)
|
23 |
gr.LoginButton()
|
24 |
gr.LogoutButton()
|
25 |
-
|
26 |
inp = gr.File(file_types=['.epub'])
|
27 |
-
inp.change(self.process, inp,
|
|
|
|
|
28 |
demo.launch()
|
29 |
|
30 |
def process(self, file, profile: gr.OAuthProfile | None):
|
31 |
if profile is None:
|
32 |
return gr.update(value='Login to access the tool.')
|
33 |
-
|
|
|
34 |
chapter_titles = epub2txt.content_titles
|
35 |
title = epub2txt.title
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
return gr.update(
|
37 |
-
value=f"# {title}\n\n" +
|
38 |
-
|
39 |
-
# [f"## {ct}\n\n{c}" for ct, c in zip(chapter_titles, ch_list)]))
|
40 |
|
41 |
def hello(self, profile: gr.OAuthProfile | None):
|
42 |
if profile is None:
|
|
|
2 |
import pip
|
3 |
import gradio as gr
|
4 |
from epub2txt import epub2txt
|
5 |
+
from websocket import create_connection
|
6 |
|
7 |
+
if not os.path.exists(os.getenv("checkpoint_path")):
|
8 |
os.system("git clone --recurse-submodules https://github.com/ztxz16/fastllm.git")
|
9 |
+
os.system("cd fastllm; mkdir build; cd build; cmake ..; make -j; cd tools; python setup.py install --user --prefix=")
|
|
|
10 |
# os.system("wget https://huggingface.co/huangyuyang/chatglm2-6b-int4.flm/resolve/main/chatglm2-6b-int4.flm")
|
11 |
+
os.system("uvicorn api:app --reload")
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
class GUI:
|
14 |
def __init__(self, *args, **kwargs):
|
|
|
17 |
gr.Markdown(scale=2).attach_load_event(self.hello, None)
|
18 |
gr.LoginButton()
|
19 |
gr.LogoutButton()
|
20 |
+
out = gr.Markdown()
|
21 |
inp = gr.File(file_types=['.epub'])
|
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:
|
29 |
return gr.update(value='Login to access the tool.')
|
30 |
+
|
31 |
+
h = ''
|
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:
|