piyazon commited on
Commit
4cae4e7
·
1 Parent(s): 9b174c5
Files changed (3) hide show
  1. Dockerfile +23 -0
  2. app.py +27 -0
  3. requirements.txt +13 -0
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.12-slim
5
+
6
+ # Install system dependencies for torch and audio
7
+ RUN apt-get update && apt-get install -y \
8
+ ffmpeg \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ RUN useradd -m -u 1000 user
12
+ USER user
13
+ ENV PATH="/home/user/.local/bin:$PATH"
14
+
15
+ WORKDIR /app
16
+
17
+ COPY --chown=user ./requirements.txt requirements.txt
18
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
19
+
20
+ COPY --chown=user . /app
21
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
22
+
23
+
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ import torchaudio
4
+ import torchcodec
5
+ from fastapi import FastAPI, UploadFile, File, Form, HTTPException
6
+ from fastapi.responses import JSONResponse
7
+ from fastapi.middleware.cors import CORSMiddleware
8
+ from transformers import Wav2Vec2BertProcessor, AutoModelForCTC
9
+ from pydub import AudioSegment
10
+ import tempfile
11
+ import io
12
+
13
+ app = FastAPI(title="Uyghur Speech to Text API")
14
+
15
+ # Allow specific domains or all (*) for testing
16
+ app.add_middleware(
17
+ CORSMiddleware,
18
+ allow_origins=["*"],
19
+ allow_credentials=True,
20
+ allow_methods=["*"],
21
+ allow_headers=["*"],
22
+ )
23
+
24
+ @app.get("/")
25
+ def greet_json():
26
+ return {"Hello": "World!"}
27
+
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ gradio>=4.0.0
4
+ torch>=2.0.0
5
+ torchaudio>=2.0.0
6
+ torchcodec>=0.6.0
7
+ transformers>=4.30.0
8
+ soundfile>=0.12.1
9
+ pydub
10
+ numpy
11
+ huggingface_hub
12
+ umsc
13
+ pypinyin