arcsu1 commited on
Commit
6eccb18
·
1 Parent(s): 58dfeed
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from flask import Flask
 
2
  from fastapi_app import fastapi_app
3
  from werkzeug.middleware.dispatcher import DispatcherMiddleware
4
  from werkzeug.serving import run_simple
@@ -11,6 +12,20 @@ flask_app = Flask(__name__)
11
  def flask_hello():
12
  return 'Hello from Flask!'
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Combine Flask and FastAPI using DispatcherMiddleware
15
  application = DispatcherMiddleware(flask_app, {
16
  '/fastapi': fastapi_app
 
1
  from flask import Flask
2
+ import requests
3
  from fastapi_app import fastapi_app
4
  from werkzeug.middleware.dispatcher import DispatcherMiddleware
5
  from werkzeug.serving import run_simple
 
12
  def flask_hello():
13
  return 'Hello from Flask!'
14
 
15
+ def hello_from_fastapi():
16
+ # Make an HTTP request to the FastAPI route
17
+ response = requests.get('http://localhost:7860/fastapi')
18
+ if response.status_code == 200:
19
+ return response.json()
20
+ else:
21
+ return {"error": "Failed to fetch from FastAPI"}
22
+
23
+ # Create a new Flask route to use the hello_from_fastapi function
24
+ @flask_app.route('/fetch-from-fastapi')
25
+ def fetch_from_fastapi():
26
+ result = hello_from_fastapi()
27
+ return result
28
+
29
  # Combine Flask and FastAPI using DispatcherMiddleware
30
  application = DispatcherMiddleware(flask_app, {
31
  '/fastapi': fastapi_app