Spaces:
Sleeping
Sleeping
Trae Assistant commited on
Commit ·
779c78b
1
Parent(s): e4b7266
优化
Browse files- .dockerignore +10 -0
- Dockerfile +14 -2
- app.py +3 -0
- templates/index.html +2 -2
.dockerignore
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.git
|
| 2 |
+
.gitignore
|
| 3 |
+
__pycache__
|
| 4 |
+
*.pyc
|
| 5 |
+
*.pyo
|
| 6 |
+
*.pyd
|
| 7 |
+
.DS_Store
|
| 8 |
+
instance/
|
| 9 |
+
venv/
|
| 10 |
+
.env
|
Dockerfile
CHANGED
|
@@ -1,5 +1,10 @@
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
COPY requirements.txt .
|
|
@@ -7,9 +12,16 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 7 |
|
| 8 |
COPY . .
|
| 9 |
|
| 10 |
-
# Create instance directory
|
|
|
|
| 11 |
RUN mkdir -p instance && chmod 777 instance
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
EXPOSE 7860
|
| 14 |
|
| 15 |
-
CMD ["
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
+
# Prevent Python from writing pyc files to disc
|
| 4 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 5 |
+
# Prevent Python from buffering stdout and stderr
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
|
| 8 |
WORKDIR /app
|
| 9 |
|
| 10 |
COPY requirements.txt .
|
|
|
|
| 12 |
|
| 13 |
COPY . .
|
| 14 |
|
| 15 |
+
# Create instance directory and fix permissions
|
| 16 |
+
# We use chmod 777 to allow the non-root user (or any user HF assigns) to write to it
|
| 17 |
RUN mkdir -p instance && chmod 777 instance
|
| 18 |
|
| 19 |
+
# Create a non-root user
|
| 20 |
+
RUN useradd -m -u 1000 user
|
| 21 |
+
|
| 22 |
+
# Switch to the non-root user
|
| 23 |
+
USER user
|
| 24 |
+
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
|
app.py
CHANGED
|
@@ -31,6 +31,7 @@ def close_connection(exception):
|
|
| 31 |
db.close()
|
| 32 |
|
| 33 |
def init_db():
|
|
|
|
| 34 |
with app.app_context():
|
| 35 |
db = get_db()
|
| 36 |
# Asteroids Catalog (Candidates)
|
|
@@ -76,8 +77,10 @@ def init_db():
|
|
| 76 |
]
|
| 77 |
db.executemany('INSERT INTO asteroids (name, type, distance_au, diameter_km, estimated_value_t, spectral_class, composition) VALUES (?, ?, ?, ?, ?, ?, ?)', seed_data)
|
| 78 |
db.commit()
|
|
|
|
| 79 |
|
| 80 |
init_db()
|
|
|
|
| 81 |
|
| 82 |
# --- AI Integration ---
|
| 83 |
def ai_analyze_asteroid(asteroid_data):
|
|
|
|
| 31 |
db.close()
|
| 32 |
|
| 33 |
def init_db():
|
| 34 |
+
print("Initializing database check...", flush=True)
|
| 35 |
with app.app_context():
|
| 36 |
db = get_db()
|
| 37 |
# Asteroids Catalog (Candidates)
|
|
|
|
| 77 |
]
|
| 78 |
db.executemany('INSERT INTO asteroids (name, type, distance_au, diameter_km, estimated_value_t, spectral_class, composition) VALUES (?, ?, ?, ?, ?, ?, ?)', seed_data)
|
| 79 |
db.commit()
|
| 80 |
+
print("Database seeded.", flush=True)
|
| 81 |
|
| 82 |
init_db()
|
| 83 |
+
print("App loaded.", flush=True)
|
| 84 |
|
| 85 |
# --- AI Integration ---
|
| 86 |
def ai_analyze_asteroid(asteroid_data):
|
templates/index.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
| 10 |
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
| 11 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
| 12 |
<style>
|
| 13 |
-
[v-cloak] { display: none; }
|
| 14 |
body { background-color: #f8fafc; color: #0f172a; }
|
| 15 |
.prose h1, .prose h2, .prose h3 { color: #1e3a8a; margin-top: 1em; margin-bottom: 0.5em; font-weight: 700; }
|
| 16 |
.prose ul { list-style-type: disc; padding-left: 1.5em; }
|
|
@@ -489,7 +489,7 @@
|
|
| 489 |
fileInput
|
| 490 |
};
|
| 491 |
}
|
| 492 |
-
});
|
| 493 |
</script>
|
| 494 |
</body>
|
| 495 |
</html>
|
|
|
|
| 10 |
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
| 11 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
| 12 |
<style>
|
| 13 |
+
[v-cloak] { display: none !important; }
|
| 14 |
body { background-color: #f8fafc; color: #0f172a; }
|
| 15 |
.prose h1, .prose h2, .prose h3 { color: #1e3a8a; margin-top: 1em; margin-bottom: 0.5em; font-weight: 700; }
|
| 16 |
.prose ul { list-style-type: disc; padding-left: 1.5em; }
|
|
|
|
| 489 |
fileInput
|
| 490 |
};
|
| 491 |
}
|
| 492 |
+
}).mount('#app');
|
| 493 |
</script>
|
| 494 |
</body>
|
| 495 |
</html>
|