Reyall commited on
Commit
f7dc5a0
·
verified ·
1 Parent(s): 6e65219

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +46 -21
src/streamlit_app.py CHANGED
@@ -1,6 +1,22 @@
1
  import streamlit as st
2
- from pydub import AudioSegment
3
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  # -----------------------------
6
  # Streamlit UI
@@ -11,34 +27,43 @@ st.write("Audio faylı yükləyin və tibbi insight çıxarın.")
11
  uploaded_file = st.file_uploader("Audio seçin (.wav, .mp3, .ogg, .m4a)", type=["wav","mp3","ogg","m4a"])
12
 
13
  if uploaded_file is not None:
14
- # 1️⃣ Audio → wav
15
- wav_path = "temp.wav"
16
- audio = AudioSegment.from_file(uploaded_file)
17
- audio.export(wav_path, format="wav")
18
 
19
- st.audio(wav_path, format="audio/wav")
20
-
21
- # 2️⃣ ASR Model (Whisper, public)
22
  with st.spinner("Audio tanınır..."):
23
- asr = pipeline(
24
- "automatic-speech-recognition",
25
- model="openai/whisper-large-v2"
26
- )
27
- az_text = asr(wav_path, generate_kwargs={"task":"transcribe", "language":"az"})["text"].strip()
28
- en_text = asr(wav_path, generate_kwargs={"task":"translate", "language":"az"})["text"].strip()
29
 
30
  st.subheader("🎧 Transcripts")
31
  st.write("AZ:", az_text)
32
  st.write("EN:", en_text)
33
 
34
- # 3️⃣ LLM Model (Public, instruct)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  with st.spinner("Tibbi insight hazırlanır..."):
36
- llm = pipeline(
37
- "text-generation",
38
- model="tiiuae/falcon-7b-instruct"
 
 
39
  )
40
- insight_output = llm(f"Xəstənin vəziyyəti barədə tibbi təhlil ver:\n{az_text}",
41
- max_new_tokens=200)[0]["generated_text"].strip()
42
 
43
  st.subheader("💡 MODEL INSIGHT")
44
- st.write(insight_output)
 
1
  import streamlit as st
 
2
  from transformers import pipeline
3
+ from openai import OpenAI
4
+
5
+ # -----------------------------
6
+ # Hugging Face API Token (Secrets-də saxla!)
7
+ # -----------------------------
8
+ HF_TOKEN = st.secrets["HF_TOKEN"]
9
+
10
+ client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=HF_TOKEN)
11
+
12
+ # -----------------------------
13
+ # ASR Pipeline (Whisper)
14
+ # -----------------------------
15
+ @st.cache_resource
16
+ def load_asr():
17
+ return pipeline("automatic-speech-recognition", model="openai/whisper-large-v3")
18
+
19
+ asr = load_asr()
20
 
21
  # -----------------------------
22
  # Streamlit UI
 
27
  uploaded_file = st.file_uploader("Audio seçin (.wav, .mp3, .ogg, .m4a)", type=["wav","mp3","ogg","m4a"])
28
 
29
  if uploaded_file is not None:
30
+ st.audio(uploaded_file, format='audio/wav')
 
 
 
31
 
 
 
 
32
  with st.spinner("Audio tanınır..."):
33
+ az_text = asr(uploaded_file, generate_kwargs={"task":"transcribe","language":"az"})["text"].strip()
34
+ en_text = asr(uploaded_file, generate_kwargs={"task":"translate","language":"az"})["text"].strip()
 
 
 
 
35
 
36
  st.subheader("🎧 Transcripts")
37
  st.write("AZ:", az_text)
38
  st.write("EN:", en_text)
39
 
40
+ # -----------------------------
41
+ # LLM → Insight
42
+ # -----------------------------
43
+ messages = [
44
+ {
45
+ "role": "system",
46
+ "content": (
47
+ "Sən tibbi köməkçi modelsən. Məqsədin xəstənin danışığından simptomları, "
48
+ "həyati əlamətləri və təcili prioriteti müəyyən etməkdir. "
49
+ "Qısa və analitik cavab ver, tibbi anlayışlara əsaslan."
50
+ )
51
+ },
52
+ {
53
+ "role": "user",
54
+ "content": f"Mətn: {az_text}\n\nXəstənin vəziyyəti barədə tibbi təhlil ver:"
55
+ }
56
+ ]
57
+
58
  with st.spinner("Tibbi insight hazırlanır..."):
59
+ completion = client.chat.completions.create(
60
+ model="Intelligent-Internet/II-Medical-8B-1706:featherless-ai",
61
+ messages=messages,
62
+ max_tokens=400,
63
+ temperature=0.4
64
  )
65
+
66
+ llm_response = completion.choices[0].message.content.strip()
67
 
68
  st.subheader("💡 MODEL INSIGHT")
69
+ st.write(llm_response)