from vocca_ai.ai_response import generate_call_summary
from vocca_ai.intent_classifier import classify_intent
from vocca_ai.sentiment import analyze_sentiment
from vocca_ai.db_handler import log_call, fetch_recent_calls
import streamlit as st
from vocca_ai.preprocess import priority_score
from vocca_ai.intent_classifier import classify_intent 



import sys
import os

# this line ensures Python can find the 'models' directory
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

st.title("🩺 AI-Powered Call Insights for Vocca")
st.write("Analyze patient calls, detect urgency, and generate AI-powered responses.")

user_input = st.text_area("📞 Enter Call Transcript:", height=250)

if user_input:
    intent = classify_intent(user_input)
    priority = priority_score(user_input)
    sentiment = analyze_sentiment(user_input)  # Now using DistilBERT
    ai_response = generate_call_summary(user_input)  # Now using Falcon-7B

    st.subheader(" Extracted Call Insights")
    st.write(f"**Intent:** {intent}")
    st.write(f"**Priority Level:** {priority}")
    st.write(f"**Sentiment:** {sentiment}")
    st.write(f"**AI Suggested Response:** {ai_response}")

    log_call(user_input, intent, priority, sentiment, ai_response)

    st.success("✅ Call successfully logged & analyzed!")

if st.button("📊 Show Recent Calls"):
    calls = fetch_recent_calls()
    st.subheader("📊 Recent Call Logs")
    for row in calls:
        st.write(f" **Transcript:** {row[1]}")
        st.write(f" **Intent:** {row[2]}, **Priority:** {row[3]}, **Sentiment:** {row[4]}")
        st.write(f" **AI Response:** {row[5]}")
        st.write("---")