rastof9 commited on
Commit
c488141
·
verified ·
1 Parent(s): 206295c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -20
app.py CHANGED
@@ -1,24 +1,16 @@
1
- from flask import Flask, Response
2
 
 
3
  app = Flask(__name__)
4
 
5
- # Path to Minecraft server log
6
- LOG_FILE = "latest.log"
 
 
 
7
 
8
- @app.route("/")
9
- def stream_logs():
10
- def generate():
11
- try:
12
- with open(LOG_FILE, "r") as f:
13
- # Go to the end of file
14
- f.seek(0, 2)
15
- while True:
16
- line = f.readline()
17
- if line:
18
- yield line + "<br>"
19
- except Exception as e:
20
- yield f"Error reading log: {e}"
21
- return Response(generate(), mimetype="text/html")
22
-
23
- if __name__ == "__main__":
24
- app.run(host="0.0.0.0", port=7860)
 
1
+ from flask import Flask
2
 
3
+ # Create a Flask web application
4
  app = Flask(__name__)
5
 
6
+ # This is the main page. It will respond to Hugging Face's health checks.
7
+ @app.route('/')
8
+ def health_check():
9
+ # You can customize this message
10
+ return "This page keeps the Minecraft server's Hugging Face Space alive. The server is running in the background!"
11
 
12
+ # This runs the web server.
13
+ if __name__ == '__main__':
14
+ # It listens on all network interfaces (0.0.0.0) and on port 7860,
15
+ # which is the default port for Hugging Face Spaces.
16
+ app.run(host='0.0.0.0', port=7860)