Reyall commited on
Commit
8f26dc8
·
verified ·
1 Parent(s): ba79b68

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +29 -18
src/streamlit_app.py CHANGED
@@ -1,37 +1,50 @@
 
1
  import streamlit as st
2
- from pydub import AudioSegment
3
- from transformers import pipeline
4
  from openai import OpenAI
 
5
 
 
 
 
6
  HF_TOKEN = st.secrets["HF_TOKEN"]
 
7
  client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=HF_TOKEN)
8
 
 
 
 
9
  @st.cache_resource
10
  def load_asr():
11
  return pipeline("automatic-speech-recognition", model="openai/whisper-large-v3")
12
 
13
  asr = load_asr()
14
 
 
 
 
15
  st.title("🏥 AZ Medical Speech → Insight")
16
- st.write("Audio faylı yükləyin və tibbi insight çıxarın.")
17
 
18
  uploaded_file = st.file_uploader("Audio seçin (.wav, .mp3, .ogg, .m4a)", type=["wav", "mp3", "ogg", "m4a"])
19
 
20
  if uploaded_file is not None:
 
21
  wav_path = "temp.wav"
22
- audio = AudioSegment.from_file(uploaded_file)
23
- audio.export(wav_path, format="wav")
24
-
25
  st.audio(wav_path, format="audio/wav")
26
 
27
- with st.spinner("Audio tanınır..."):
28
- az_text = asr(wav_path, generate_kwargs={"task": "transcribe", "language": "az"})["text"].strip()
29
- en_text = asr(wav_path, generate_kwargs={"task": "translate", "language": "az"})["text"].strip()
30
 
31
  st.subheader("🎧 Transcripts")
32
  st.write("AZ:", az_text)
33
  st.write("EN:", en_text)
34
 
 
35
  messages = [
36
  {
37
  "role": "system",
@@ -47,16 +60,14 @@ if uploaded_file is not None:
47
  }
48
  ]
49
 
50
- with st.spinner("Tibbi insight hazırlanır..."):
51
- completion = client.chat.completions.create(
52
- model="Intelligent-Internet/II-Medical-8B-1706:featherless-ai",
53
- messages=messages,
54
- max_tokens=400,
55
- temperature=0.4
56
- )
57
 
58
- llm_response = completion.choices[0].message.content.strip()
59
 
60
  st.subheader("💡 MODEL INSIGHT")
61
  st.write(llm_response)
62
-
 
1
+ import os
2
  import streamlit as st
3
+ import soundfile as sf
 
4
  from openai import OpenAI
5
+ from transformers import pipeline
6
 
7
+ # -----------------------------
8
+ # HF Token
9
+ # -----------------------------
10
  HF_TOKEN = st.secrets["HF_TOKEN"]
11
+
12
  client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=HF_TOKEN)
13
 
14
+ # -----------------------------
15
+ # ASR Model (Whisper)
16
+ # -----------------------------
17
  @st.cache_resource
18
  def load_asr():
19
  return pipeline("automatic-speech-recognition", model="openai/whisper-large-v3")
20
 
21
  asr = load_asr()
22
 
23
+ # -----------------------------
24
+ # Streamlit UI
25
+ # -----------------------------
26
  st.title("🏥 AZ Medical Speech → Insight")
27
+ st.write("Audio yükləyin və tibbi insight çıxarın.")
28
 
29
  uploaded_file = st.file_uploader("Audio seçin (.wav, .mp3, .ogg, .m4a)", type=["wav", "mp3", "ogg", "m4a"])
30
 
31
  if uploaded_file is not None:
32
+ # Soundfile ilə .wav fayl yarat
33
  wav_path = "temp.wav"
34
+ data, samplerate = sf.read(uploaded_file)
35
+ sf.write(wav_path, data, samplerate)
36
+
37
  st.audio(wav_path, format="audio/wav")
38
 
39
+ # ASR → AZ və EN
40
+ az_text = asr(wav_path, generate_kwargs={"task": "transcribe", "language": "az"})["text"].strip()
41
+ en_text = asr(wav_path, generate_kwargs={"task": "translate", "language": "az"})["text"].strip()
42
 
43
  st.subheader("🎧 Transcripts")
44
  st.write("AZ:", az_text)
45
  st.write("EN:", en_text)
46
 
47
+ # LLM → Insight
48
  messages = [
49
  {
50
  "role": "system",
 
60
  }
61
  ]
62
 
63
+ completion = client.chat.completions.create(
64
+ model="Intelligent-Internet/II-Medical-8B-1706:featherless-ai",
65
+ messages=messages,
66
+ max_tokens=400,
67
+ temperature=0.4
68
+ )
 
69
 
70
+ llm_response = completion.choices[0].message.content.strip()
71
 
72
  st.subheader("💡 MODEL INSIGHT")
73
  st.write(llm_response)