Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -149,9 +149,24 @@ async def query(question_request: QuestionRequest):
|
|
| 149 |
raise HTTPException(status_code=500, detail="Internal Server Error")
|
| 150 |
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
@app.get("/")
|
| 153 |
-
async def
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
|
| 157 |
#if __name__ == '__main__':
|
|
|
|
| 149 |
raise HTTPException(status_code=500, detail="Internal Server Error")
|
| 150 |
|
| 151 |
|
| 152 |
+
# Define a function to run the Streamlit app
|
| 153 |
+
def run_streamlit():
|
| 154 |
+
subprocess.Popen(["streamlit", "run", "frontend.py"])
|
| 155 |
+
|
| 156 |
+
# Define a FastAPI endpoint to serve the Streamlit app
|
| 157 |
@app.get("/")
|
| 158 |
+
async def serve_streamlit():
|
| 159 |
+
# Start the Streamlit app in a background task
|
| 160 |
+
background_tasks.add_task(run_streamlit)
|
| 161 |
+
|
| 162 |
+
# Stream the output of the Streamlit app
|
| 163 |
+
streamlit_output = subprocess.Popen(["streamlit", "stream", "frontend.py", "--server.port", "8501"], stdout=subprocess.PIPE)
|
| 164 |
+
return StreamingResponse(streamlit_output.stdout, media_type="text/plain")
|
| 165 |
+
|
| 166 |
+
# Define a FastAPI endpoint to stop the Streamlit app
|
| 167 |
+
@app.get("/stop")
|
| 168 |
+
async def stop_streamlit():
|
| 169 |
+
subprocess.run(["pkill", "-f", "streamlit"])
|
| 170 |
|
| 171 |
|
| 172 |
#if __name__ == '__main__':
|