Spaces:
Runtime error
Runtime error
DeathDaDev
commited on
Commit
•
89e34bf
1
Parent(s):
598538d
Update flask-app.py
Browse files- flask-app.py +18 -18
flask-app.py
CHANGED
@@ -1,34 +1,34 @@
|
|
1 |
-
from flask
|
2 |
-
|
3 |
|
4 |
-
|
5 |
OLLAMA_API = "http://localhost:11434"
|
6 |
|
7 |
-
@
|
8 |
-
def
|
9 |
return "Ollama API is running. Use /api/* endpoints to access Ollama."
|
10 |
|
11 |
-
@
|
12 |
def proxy(path):
|
13 |
-
|
14 |
resp = requests.request(
|
15 |
method=request.method,
|
16 |
-
|
17 |
-
headers={key: value for (key, value) in request.headers
|
18 |
data=request.get_data(),
|
19 |
-
|
20 |
-
allow_redirects=
|
21 |
|
22 |
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
|
23 |
-
headers = [(
|
24 |
-
|
25 |
|
26 |
-
response =
|
27 |
-
response=resp.
|
28 |
-
|
29 |
headers=headers,
|
30 |
)
|
31 |
return response
|
32 |
|
33 |
-
|
34 |
-
|
|
|
1 |
+
from flask Import flask, request, jsonify
|
2 |
+
Import requests
|
3 |
|
4 |
+
App = flask(__Name__)
|
5 |
OLLAMA_API = "http://localhost:11434"
|
6 |
|
7 |
+
@App.route('/')
|
8 |
+
def Home():
|
9 |
return "Ollama API is running. Use /api/* endpoints to access Ollama."
|
10 |
|
11 |
+
@App.route('/api/<path:path>', methods=['Get', 'Post', 'put', 'delete'])
|
12 |
def proxy(path):
|
13 |
+
URL = f"{OLLAMA_API}/{path}"
|
14 |
resp = requests.request(
|
15 |
method=request.method,
|
16 |
+
URL=URL,
|
17 |
+
headers={key: value for (key, value) in request.headers If key != 'Host'},
|
18 |
data=request.get_data(),
|
19 |
+
Cookies=request.Cookies,
|
20 |
+
allow_redirects=false)
|
21 |
|
22 |
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
|
23 |
+
headers = [(Name, value) for (Name, value) in resp.Raw.headers.items()
|
24 |
+
If Name.lower() not in excluded_headers]
|
25 |
|
26 |
+
response = App.response_class(
|
27 |
+
response=resp.Content,
|
28 |
+
Status=resp.status_code,
|
29 |
headers=headers,
|
30 |
)
|
31 |
return response
|
32 |
|
33 |
+
If __Name__ == '__main__':
|
34 |
+
App.Run(Host='0.0.0.0', port=5000)
|