Spaces:
Sleeping
Sleeping
AdityaAdaki
commited on
Commit
·
e35edf1
1
Parent(s):
f99502b
aa
Browse files- Dockerfile +4 -6
- app.py +10 -4
Dockerfile
CHANGED
@@ -2,17 +2,15 @@ FROM python:3.9-slim
|
|
2 |
|
3 |
WORKDIR /code
|
4 |
|
5 |
-
# Create audio directory with proper permissions
|
6 |
-
RUN mkdir -p /code/static/audio && \
|
7 |
-
chmod 777 /code/static/audio
|
8 |
-
|
9 |
COPY ./requirements.txt /code/requirements.txt
|
10 |
COPY ./final_price_data.csv /code/final_price_data.csv
|
11 |
COPY ./app.py /code/app.py
|
12 |
-
COPY ./static /code/static
|
13 |
|
|
|
14 |
RUN mkdir -p /code/static/audio && \
|
15 |
-
chmod 777 /code/static
|
|
|
16 |
|
17 |
RUN apt-get update && \
|
18 |
apt-get install -y --no-install-recommends \
|
|
|
2 |
|
3 |
WORKDIR /code
|
4 |
|
|
|
|
|
|
|
|
|
5 |
COPY ./requirements.txt /code/requirements.txt
|
6 |
COPY ./final_price_data.csv /code/final_price_data.csv
|
7 |
COPY ./app.py /code/app.py
|
8 |
+
COPY ./static /code/static
|
9 |
|
10 |
+
# Ensure audio directory exists with proper permissions
|
11 |
RUN mkdir -p /code/static/audio && \
|
12 |
+
chmod -R 777 /code/static && \
|
13 |
+
chmod -R 777 /code/static/audio
|
14 |
|
15 |
RUN apt-get update && \
|
16 |
apt-get install -y --no-install-recommends \
|
app.py
CHANGED
@@ -16,10 +16,13 @@ dotenv.load_dotenv()
|
|
16 |
|
17 |
app = Flask(__name__)
|
18 |
|
19 |
-
# Create audio directory if it doesn't exist
|
20 |
-
AUDIO_DIR = Path("static/audio"
|
21 |
AUDIO_DIR.mkdir(parents=True, exist_ok=True)
|
22 |
|
|
|
|
|
|
|
23 |
def fetch_market_data(state=None, district=None, market=None, commodity=None):
|
24 |
"""Fetch data from the agricultural market API.
|
25 |
If the API fails or returns empty data, fallback to the CSV file.
|
@@ -610,10 +613,13 @@ def get_commodities():
|
|
610 |
@app.route('/static/audio/<filename>')
|
611 |
def serve_audio(filename):
|
612 |
try:
|
613 |
-
|
|
|
|
|
|
|
614 |
except Exception as e:
|
615 |
print(f"Error serving audio file: {str(e)}")
|
616 |
-
return "
|
617 |
|
618 |
if __name__ == '__main__':
|
619 |
pio.templates.default = "plotly_white"
|
|
|
16 |
|
17 |
app = Flask(__name__)
|
18 |
|
19 |
+
# Create audio directory if it doesn't exist using absolute path
|
20 |
+
AUDIO_DIR = Path(__file__).parent.absolute() / "static" / "audio"
|
21 |
AUDIO_DIR.mkdir(parents=True, exist_ok=True)
|
22 |
|
23 |
+
# Configure static folder explicitly
|
24 |
+
app.static_folder = str(Path(__file__).parent.absolute() / "static")
|
25 |
+
|
26 |
def fetch_market_data(state=None, district=None, market=None, commodity=None):
|
27 |
"""Fetch data from the agricultural market API.
|
28 |
If the API fails or returns empty data, fallback to the CSV file.
|
|
|
613 |
@app.route('/static/audio/<filename>')
|
614 |
def serve_audio(filename):
|
615 |
try:
|
616 |
+
audio_path = AUDIO_DIR / filename
|
617 |
+
if not audio_path.is_file():
|
618 |
+
return "Audio file not found", 404
|
619 |
+
return send_file(str(audio_path), mimetype="audio/mpeg")
|
620 |
except Exception as e:
|
621 |
print(f"Error serving audio file: {str(e)}")
|
622 |
+
return "Error serving audio file", 500
|
623 |
|
624 |
if __name__ == '__main__':
|
625 |
pio.templates.default = "plotly_white"
|