File size: 2,314 Bytes
5128d0c
8f26dc8
f7dc5a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5128d0c
8f26dc8
 
 
3b0bf53
6ab3905
3b0bf53
6ab3905
3b0bf53
 
f7dc5a0
6ab3905
 
f7dc5a0
 
3b0bf53
 
 
 
 
f7dc5a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ab3905
f7dc5a0
 
 
 
 
6ab3905
f7dc5a0
 
3b0bf53
 
f7dc5a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
from transformers import pipeline
from openai import OpenAI

# -----------------------------
# Hugging Face API Token (Secrets-də saxla!)
# -----------------------------
HF_TOKEN = st.secrets["HF_TOKEN"]

client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=HF_TOKEN)
# -----------------------------
# ASR Pipeline (Whisper)
# -----------------------------
@st.cache_resource
def load_asr():
    return pipeline("automatic-speech-recognition", model="openai/whisper-large-v3")

asr = load_asr()

# -----------------------------
# Streamlit UI
# -----------------------------
st.title("🏥 AZ Medical Speech → Insight")
st.write("Audio faylı yükləyin və tibbi insight çıxarın.")

uploaded_file = st.file_uploader("Audio seçin (.wav, .mp3, .ogg, .m4a)", type=["wav","mp3","ogg","m4a"])

if uploaded_file is not None:
    st.audio(uploaded_file, format='audio/wav')
    
    with st.spinner("Audio tanınır..."):
        az_text = asr(uploaded_file, generate_kwargs={"task":"transcribe","language":"az"})["text"].strip()
        en_text = asr(uploaded_file, generate_kwargs={"task":"translate","language":"az"})["text"].strip()

    st.subheader("🎧 Transcripts")
    st.write("AZ:", az_text)
    st.write("EN:", en_text)

    # -----------------------------
    # LLM → Insight
    # -----------------------------
    messages = [
        {
            "role": "system",
            "content": (
                "Sən tibbi köməkçi modelsən. Məqsədin xəstənin danışığından simptomları, "
                "həyati əlamətləri və təcili prioriteti müəyyən etməkdir. "
                "Qısa və analitik cavab ver, tibbi anlayışlara əsaslan."
            )
        },
        {
            "role": "user",
            "content": f"Mətn: {az_text}\n\nXəstənin vəziyyəti barədə tibbi təhlil ver:"
        }
    ]

    with st.spinner("Tibbi insight hazırlanır..."):
        completion = client.chat.completions.create(
            model="Intelligent-Internet/II-Medical-8B-1706:featherless-ai",
            messages=messages,
            max_tokens=400,
            temperature=0.4
        )

        llm_response = completion.choices[0].message.content.strip()

    st.subheader("💡 MODEL INSIGHT")
    st.write(llm_response)