Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -230,30 +230,37 @@ html_content = """
|
|
230 |
</body>
|
231 |
</html>
|
232 |
"""
|
233 |
-
|
234 |
-
# FastAPI route to display HTML interface
|
235 |
@app.get("/", response_class=HTMLResponse)
|
236 |
-
async def
|
|
|
237 |
status = "Running" if running else "Stopped"
|
238 |
-
return HTMLResponse(html_content.replace("{{ status }}", status))
|
239 |
|
240 |
-
#
|
241 |
-
@app.get("/start")
|
242 |
async def start_processing():
|
243 |
global running, loop_thread
|
244 |
if not running:
|
245 |
running = True
|
246 |
-
loop_thread = threading.Thread(target=email_processing_loop)
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
|
251 |
-
#
|
252 |
-
@app.get("/stop")
|
253 |
async def stop_processing():
|
254 |
global running
|
255 |
-
running
|
256 |
-
|
|
|
|
|
257 |
|
258 |
if __name__ == "__main__":
|
259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
230 |
</body>
|
231 |
</html>
|
232 |
"""
|
233 |
+
# Endpoint to display the home page with the email processor's status
|
|
|
234 |
@app.get("/", response_class=HTMLResponse)
|
235 |
+
async def home():
|
236 |
+
global running
|
237 |
status = "Running" if running else "Stopped"
|
238 |
+
return HTMLResponse(content=html_content.replace("{{ status }}", status), status_code=200)
|
239 |
|
240 |
+
# Endpoint to start the email processing loop
|
241 |
+
@app.get("/start", response_class=HTMLResponse)
|
242 |
async def start_processing():
|
243 |
global running, loop_thread
|
244 |
if not running:
|
245 |
running = True
|
246 |
+
loop_thread = threading.Thread(target=email_processing_loop, daemon=True)
|
247 |
+
loop_thread.start()
|
248 |
+
status = "Running"
|
249 |
+
return HTMLResponse(content=html_content.replace("{{ status }}", status), status_code=200)
|
250 |
|
251 |
+
# Endpoint to stop the email processing loop
|
252 |
+
@app.get("/stop", response_class=HTMLResponse)
|
253 |
async def stop_processing():
|
254 |
global running
|
255 |
+
if running:
|
256 |
+
running = False
|
257 |
+
status = "Stopped"
|
258 |
+
return HTMLResponse(content=html_content.replace("{{ status }}", status), status_code=200)
|
259 |
|
260 |
if __name__ == "__main__":
|
261 |
+
print('starting')
|
262 |
+
logging.info('starting project!...')
|
263 |
+
# running = True
|
264 |
+
# threading.Thread(target=email_processing_loop, daemon=True).start()
|
265 |
+
logging.info('...')
|
266 |
+
uvicorn.run()
|