Spaces:
Sleeping
Sleeping
Yang commited on
Commit ·
5ca73ce
1
Parent(s): 0ab452d
Add application file
Browse files- Dockerfile +6 -0
- app.py +28 -0
- requirements.txt +2 -0
Dockerfile
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY . .
|
| 4 |
+
RUN pip install flask
|
| 5 |
+
EXPOSE 7860
|
| 6 |
+
CMD ["flask", "run", "--host=0.0.0.0", "--port=7860"]
|
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
URLS = [
|
| 7 |
+
"https://example1.com",
|
| 8 |
+
"https://example2.com",
|
| 9 |
+
"https://example3.com",
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@app.route("/")
|
| 14 |
+
def get_url():
|
| 15 |
+
failed = request.args.get("failed")
|
| 16 |
+
|
| 17 |
+
urls = URLS.copy()
|
| 18 |
+
|
| 19 |
+
if not urls:
|
| 20 |
+
return jsonify({"error": "URL list is empty"})
|
| 21 |
+
|
| 22 |
+
if failed:
|
| 23 |
+
urls = [u for u in urls if u != failed]
|
| 24 |
+
|
| 25 |
+
if not urls:
|
| 26 |
+
return jsonify({"error": "No URLs remaining after filtering"})
|
| 27 |
+
|
| 28 |
+
return jsonify({"url": random.choice(urls)})
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
jsonify
|