DeathDaDev commited on
Commit
ea5c2f9
1 Parent(s): eba0ee0

Add live logs and API endpoints to the web interface.

Browse files
Files changed (2) hide show
  1. app.py +10 -18
  2. templates/index.html +2 -0
app.py CHANGED
@@ -1,28 +1,20 @@
1
  import os
2
- from flask import Flask, render_template
 
3
 
4
  app = Flask(__name__)
5
 
6
  @app.route("/")
7
  def index():
8
- logs = ""
9
- with open("logs.txt", "r") as f:
10
- logs = f.read()
11
- return render_template("index.html", logs=logs)
12
 
13
- if __name__ == "__main__":
14
- app.run(host="0.0.0.0", port=5000, debug=True)
15
-
16
- app = Flask(__name__)
17
-
18
- @app.route("/")
19
- def index():
20
- return render_template("index.html", logs_url="/logs")
21
 
22
  if __name__ == "__main__":
23
  app.run(host="0.0.0.0", port=5000, debug=True)
24
- @app.route("/logs")
25
- def logs():
26
- with open("logs.txt", "r") as f:
27
- logs = f.read()
28
- return logs
 
1
  import os
2
+ import subprocess
3
+ from flask import Flask, render_template, Response
4
 
5
  app = Flask(__name__)
6
 
7
  @app.route("/")
8
  def index():
9
+ return render_template("index.html", logs_url="/logs", api_url="/api/generate")
 
 
 
10
 
11
+ @app.route("/logs")
12
+ def logs():
13
+ def stream_logs():
14
+ process = subprocess.Popen(["docker-compose", "logs", "-f", "ollama"], stdout=subprocess.PIPE)
15
+ for line in iter(process.stdout.readline, b''):
16
+ yield line.decode('utf-8')
17
+ return Response(stream_logs(), mimetype='text/plain')
 
18
 
19
  if __name__ == "__main__":
20
  app.run(host="0.0.0.0", port=5000, debug=True)
 
 
 
 
 
templates/index.html CHANGED
@@ -15,6 +15,8 @@
15
  <li><code>/translate</code>: Translate text</li>
16
  <li><code>/summarize</code>: Summarize text</li>
17
  <li><code>/question</code>: Answer a question</li>
 
 
18
  </ul>
19
  </body>
20
  </html>
 
15
  <li><code>/translate</code>: Translate text</li>
16
  <li><code>/summarize</code>: Summarize text</li>
17
  <li><code>/question</code>: Answer a question</li>
18
+ <li><code>/completion</code>: Complete text</li>
19
+ <li><code>/embedding</code>: Get embeddings for text</li>
20
  </ul>
21
  </body>
22
  </html>