Joe6636564 commited on
Commit
4899a6d
·
verified ·
1 Parent(s): 2949c89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -258,6 +258,28 @@ def get_models():
258
  def run_flask():
259
  flask_app.run(host='0.0.0.0', port=5000, debug=False, threaded=True)
260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  def run_gradio():
262
  # CSS for the interface
263
  CSS = """.duplicate-button { margin: auto !important; color: white !important; background: black !important; border-radius: 100vh !important;}h3 { text-align: center;}"""
 
258
  def run_flask():
259
  flask_app.run(host='0.0.0.0', port=5000, debug=False, threaded=True)
260
 
261
+ def forward_flask(path, request):
262
+ import requests
263
+ url = f"http://localhost:5000/{path}"
264
+
265
+ if request.method == "POST":
266
+ r = requests.post(url, json=request.json)
267
+ else:
268
+ r = requests.get(url)
269
+ return r.json()
270
+
271
+ api = gr.routes.App.create_app()
272
+ api.router.add_api_route(
273
+ "/api/chat",
274
+ forward_flask,
275
+ methods=["POST"]
276
+ )
277
+ api.router.add_api_route(
278
+ "/api/vision",
279
+ forward_flask,
280
+ methods=["POST"]
281
+ )
282
+
283
  def run_gradio():
284
  # CSS for the interface
285
  CSS = """.duplicate-button { margin: auto !important; color: white !important; background: black !important; border-radius: 100vh !important;}h3 { text-align: center;}"""