Spaces:
Paused
Paused
matthoffner
commited on
Commit
•
436e2b0
1
Parent(s):
1ea029d
Update main.py
Browse files
main.py
CHANGED
@@ -31,79 +31,6 @@ async def index():
|
|
31 |
return HTMLResponse(content=html_content, status_code=200)
|
32 |
|
33 |
|
34 |
-
@app.get("/demo")
|
35 |
-
async def demo():
|
36 |
-
html_content = """
|
37 |
-
<!DOCTYPE html>
|
38 |
-
<html>
|
39 |
-
<head>
|
40 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.1/showdown.min.js"></script>
|
41 |
-
</head>
|
42 |
-
<body>
|
43 |
-
<style>
|
44 |
-
body {
|
45 |
-
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
|
46 |
-
}
|
47 |
-
code {
|
48 |
-
font-family: "SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace !important;
|
49 |
-
display: inline-block;
|
50 |
-
background-color: lightgray;
|
51 |
-
}
|
52 |
-
h1 h2 h3 h4 h5 h6 {
|
53 |
-
font-family: Roboto,-apple-system,BlinkMacSystemFont,"Helvetica Neue","Segoe UI","Oxygen","Ubuntu","Cantarell","Open Sans",sans-serif;
|
54 |
-
}
|
55 |
-
#content {
|
56 |
-
box-sizing: border-box;
|
57 |
-
min-width: 200px;
|
58 |
-
max-width: 980px;
|
59 |
-
margin: 0 auto;
|
60 |
-
padding: 45px;
|
61 |
-
font-size: 16px;
|
62 |
-
}
|
63 |
-
@media (max-width: 767px) {
|
64 |
-
#content {
|
65 |
-
padding: 15px;
|
66 |
-
}
|
67 |
-
}
|
68 |
-
</style>
|
69 |
-
|
70 |
-
<script type="module" src="https://cdn.skypack.dev/@vanillawc/wc-markdown"></script>
|
71 |
-
<wc-markdown id="content" highlight><h1>starchat-alpha-q4.0</h1></wc-markdown>
|
72 |
-
|
73 |
-
<script>
|
74 |
-
var converter = new showdown.Converter();
|
75 |
-
var source = new EventSource("https://matthoffner-starchat-alpha.hf.space/stream");
|
76 |
-
let eventCache;
|
77 |
-
source.onmessage = function(event) {
|
78 |
-
let eventData = event.data;
|
79 |
-
console.log(eventData);
|
80 |
-
if (eventData.includes("```")) {
|
81 |
-
eventCache = true;
|
82 |
-
return;
|
83 |
-
}
|
84 |
-
if (eventCache && !eventData.includes("```")) {
|
85 |
-
backticks = "```";
|
86 |
-
eventData = `${backticks}${eventData}<br /><code>`;
|
87 |
-
eventCache = false;
|
88 |
-
}
|
89 |
-
if (eventData === ":") {
|
90 |
-
eventData = `${eventData}<br />`;
|
91 |
-
}
|
92 |
-
if (eventData === "<|assistant|>") {
|
93 |
-
eventData = `<br />${eventData}`;
|
94 |
-
}
|
95 |
-
if (eventData === "<|end|>") {
|
96 |
-
eventData = "<br />";
|
97 |
-
}
|
98 |
-
document.getElementById("content").innerHTML = document.getElementById("content").innerHTML + eventData;
|
99 |
-
};
|
100 |
-
</script>
|
101 |
-
|
102 |
-
</body>
|
103 |
-
</html>
|
104 |
-
"""
|
105 |
-
return HTMLResponse(content=html_content, status_code=200)
|
106 |
-
|
107 |
@app.get("/stream")
|
108 |
async def chat(prompt = "<|user|> Write an express server with server sent events. <|assistant|>"):
|
109 |
tokens = llm.tokenize(prompt)
|
|
|
31 |
return HTMLResponse(content=html_content, status_code=200)
|
32 |
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
@app.get("/stream")
|
35 |
async def chat(prompt = "<|user|> Write an express server with server sent events. <|assistant|>"):
|
36 |
tokens = llm.tokenize(prompt)
|