Update src/streamlit_app.py
Browse files- 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 |
-
|
| 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 |
-
|
| 24 |
-
|
| 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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
with st.spinner("Tibbi insight hazırlanır..."):
|
| 36 |
-
|
| 37 |
-
"
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
st.subheader("💡 MODEL INSIGHT")
|
| 44 |
-
st.write(
|
|
|
|
| 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)
|