matthoffner commited on
Commit
8822968
Β·
1 Parent(s): e891fce

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +43 -3
main.py CHANGED
@@ -23,11 +23,51 @@ app.add_middleware(
23
 
24
  @app.get("/")
25
  async def index():
26
- with open("README.md", "r", encoding="utf-8") as readme_file:
27
- md_template_string = readme_file.read()
28
- html_content = markdown.markdown(md_template_string)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  return HTMLResponse(content=html_content, status_code=200)
30
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  class ChatCompletionRequest(BaseModel):
32
  prompt: str
33
 
 
23
 
24
  @app.get("/")
25
  async def index():
26
+ html_content = """
27
+ <!DOCTYPE html>
28
+ <html>
29
+ <style>
30
+ body {
31
+ font-family: "Arial";
32
+ }
33
+ h1 {
34
+ text-align: "center";
35
+ }
36
+ </style>
37
+ <body>
38
+ <h1>gorilla</h1>
39
+ <input id="prompt" type="text">
40
+ <button id="search">I'm feeling lucky</button>
41
+ <div id="content"></div>
42
+ <script>
43
+ document.getElementById("search").addEventListener(('click') => {
44
+ let prompt = document.getElementById("prompt").innerText;
45
+ let source = new EventSource(`https://matthoffner-gorilla.hf.space/stream?prompt=${prompt}`);
46
+ document.getElmentById("content").innerHtml = "";
47
+ source.onmessage = function(event) {
48
+ let eventData = event.data;
49
+ document.getElementById("content").innerHTML += eventData
50
+ };
51
+ })
52
+
53
+ </script>
54
+ </body>
55
+ </html>
56
+ """
57
  return HTMLResponse(content=html_content, status_code=200)
58
 
59
+ @app.get("/stream")
60
+ async def chat(prompt = "I want to download a dataset from GCS"):
61
+ tokens = llm.tokenize(prompt)
62
+ async def server_sent_events(chat_chunks, llm):
63
+ yield prompt
64
+ for chat_chunk in llm.generate(chat_chunks):
65
+ yield llm.detokenize(chat_chunk)
66
+ yield ""
67
+
68
+ return EventSourceResponse(server_sent_events(tokens, llm))
69
+
70
+
71
  class ChatCompletionRequest(BaseModel):
72
  prompt: str
73