HilmiZr commited on
Commit
a741559
·
1 Parent(s): c833759

requirements, app.py

Browse files
Files changed (3) hide show
  1. Dockerfile +6 -5
  2. requirements.txt +4 -1
  3. src/streamlit_app.py +31 -34
Dockerfile CHANGED
@@ -2,6 +2,9 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
 
 
 
5
  RUN apt-get update && apt-get install -y \
6
  build-essential \
7
  curl \
@@ -14,8 +17,6 @@ COPY src/ ./src/
14
 
15
  RUN pip3 install -r requirements.txt
16
 
17
- EXPOSE 8501
18
-
19
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
-
21
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
2
 
3
  WORKDIR /app
4
 
5
+ RUN mkdir -p /.streamlit && chmod 777 /.streamlit
6
+ RUN mkdir -p /tmp && chmod 777 /tmp
7
+
8
  RUN apt-get update && apt-get install -y \
9
  build-essential \
10
  curl \
 
17
 
18
  RUN pip3 install -r requirements.txt
19
 
20
+ EXPOSE 7860
21
+ HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health
22
+ ENTRYPOINT ["streamlit", "run", ..., "--server.port=7860"]
 
 
requirements.txt CHANGED
@@ -1,3 +1,6 @@
1
  altair
2
  pandas
3
- streamlit
 
 
 
 
1
  altair
2
  pandas
3
+ streamlit
4
+ openai-whisper
5
+ torch
6
+ torchaudio
src/streamlit_app.py CHANGED
@@ -1,40 +1,37 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
- import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
 
 
 
 
 
8
 
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
 
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
 
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
 
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
 
 
 
 
25
 
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
 
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
1
+ import os
2
+ os.environ["STREAMLIT_HOME"] = "/tmp"
3
+ os.environ["MPLCONFIGDIR"] = "/tmp"
4
+ os.environ["STREAMLIT_BROWSER_GATHER_USAGE_STATS"] = "false"
5
+ os.environ["STREAMLIT_WATCHER_TYPE"] = "none"
6
+
7
+ import asyncio
8
+ try:
9
+ asyncio.get_running_loop()
10
+ except RuntimeError:
11
+ loop = asyncio.new_event_loop()
12
+ asyncio.set_event_loop(loop)
13
 
14
+ import streamlit as st
15
+ import whisper
16
+ import uuid
 
 
 
17
 
18
+ st.title("🧪 Whisper Tiny ASR (No Diarization)")
19
+ st.write("Upload an audio file (wav/mp3/m4a) and get a quick transcription using Whisper Tiny.")
20
 
21
+ uploaded = st.file_uploader("Choose an audio file", type=["wav", "mp3", "m4a", "flac"])
 
 
22
 
23
+ if uploaded:
24
+ audio_id = uuid.uuid4().hex
25
+ audio_path = f"/tmp/audio_{audio_id}.wav"
26
+ with open(audio_path, "wb") as f:
27
+ f.write(uploaded.read())
28
+ st.success(f"✅ File saved to {audio_path}")
29
 
30
+ if st.button("Transcribe"):
31
+ with st.spinner("Loading Whisper (tiny)..."):
32
+ model = whisper.load_model("tiny").to("cpu")
 
 
 
33
 
34
+ with st.spinner("Transcribing..."):
35
+ result = model.transcribe(audio_path, language="id")
36
+ st.header("📝 Transcription Result")
37
+ st.markdown(result["text"])