Yuvrajspd09 commited on
Commit
20d97e8
·
1 Parent(s): 9358cf1

Moved vocca_ai to root for Hugging Face deployment

Browse files
app.py CHANGED
@@ -4,7 +4,9 @@ from vocca_ai.sentiment import analyze_sentiment
4
  from vocca_ai.db_handler import log_call, fetch_recent_calls
5
  import streamlit as st
6
  from vocca_ai.preprocess import priority_score
7
- from vocca_ai.intent_classifier import classify_intent # Now uses MiniLM
 
 
8
 
9
  import sys
10
  import os
 
4
  from vocca_ai.db_handler import log_call, fetch_recent_calls
5
  import streamlit as st
6
  from vocca_ai.preprocess import priority_score
7
+ from vocca_ai.intent_classifier import classify_intent
8
+
9
+
10
 
11
  import sys
12
  import os
vocca_ai/__init__.py ADDED
File without changes
vocca_ai/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (170 Bytes). View file
 
vocca_ai/__pycache__/ai_response.cpython-311.pyc ADDED
Binary file (1.49 kB). View file
 
vocca_ai/__pycache__/db_handler.cpython-311.pyc ADDED
Binary file (1.57 kB). View file
 
vocca_ai/__pycache__/intent_classifier.cpython-311.pyc ADDED
Binary file (2.47 kB). View file
 
vocca_ai/__pycache__/preprocess.cpython-311.pyc ADDED
Binary file (892 Bytes). View file
 
vocca_ai/__pycache__/sentiment.cpython-311.pyc ADDED
Binary file (1.14 kB). View file
 
vocca_ai/ai_response.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
+
3
+ # Load a high-quality summarization model
4
+ model_name = "google/flan-t5-large"
5
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
6
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
7
+
8
+ def generate_call_summary(transcript):
9
+ """
10
+ Generates a structured and useful summary of the call.
11
+ """
12
+ input_text = f"Summarize this medical call conversation:\n{transcript}"
13
+ inputs = tokenizer(input_text, return_tensors="pt", truncation=True)
14
+ outputs = model.generate(**inputs, max_length=100, min_length=20, length_penalty=2.0, num_beams=5)
15
+
16
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
17
+
18
+ # Example Usage
19
+ if __name__ == "__main__":
20
+ sample_text = "Patient: Hi, I need to schedule an appointment as soon as possible. I’ve been feeling really weak and dizzy for the past few days."
21
+ print(f"Call Summary: {generate_call_summary(sample_text)}")
vocca_ai/db_handler.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+
3
+ # Allow database access from multiple threads
4
+ conn = sqlite3.connect("call_logs.db", check_same_thread=False)
5
+ c = conn.cursor()
6
+
7
+ # Create Table for Logging Calls
8
+ c.execute('''CREATE TABLE IF NOT EXISTS call_logs
9
+ (id INTEGER PRIMARY KEY, transcript TEXT, intent TEXT, priority TEXT, sentiment TEXT, ai_response TEXT)''')
10
+ conn.commit()
11
+
12
+ def log_call(transcript, intent, priority, sentiment, ai_response):
13
+ """Save the call analysis results to database."""
14
+ c.execute("INSERT INTO call_logs (transcript, intent, priority, sentiment, ai_response) VALUES (?, ?, ?, ?, ?)",
15
+ (transcript, intent, priority, sentiment, ai_response))
16
+ conn.commit()
17
+
18
+ def fetch_recent_calls(limit=5):
19
+ """Fetch latest logged calls from database."""
20
+ c.execute("SELECT * FROM call_logs ORDER BY id DESC LIMIT ?", (limit,))
21
+ return c.fetchall()
vocca_ai/intent_classifier.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def classify_intent(text):
2
+ """
3
+ Classifies the intent based on keyword matching (simple rule-based approach).
4
+ """
5
+ text_lower = text.lower()
6
+
7
+ if any(word in text_lower for word in ["urgent", "emergency", "immediate", "asap", "critical"]):
8
+ return "urgent medical need"
9
+ if any(word in text_lower for word in ["appointment", "schedule", "book a visit", "doctor visit"]):
10
+ return "non-urgent appointment"
11
+ if any(word in text_lower for word in ["billing", "charge", "invoice", "cost"]):
12
+ return "billing inquiry"
13
+ if any(word in text_lower for word in ["insurance", "coverage", "policy"]):
14
+ return "insurance information"
15
+ if any(word in text_lower for word in ["pain", "health issue", "fever", "symptom", "sick"]):
16
+ return "medical advice"
17
+
18
+ return "general inquiry"
19
+
20
+ # Example Usage
21
+ if __name__ == "__main__":
22
+ sample_text = "I need to book an appointment for my uncle who is feeling sick."
23
+ print(f"Intent: {classify_intent(sample_text)}")
vocca_ai/preprocess.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ def priority_score(text):
2
+ urgent_keywords = ["emergency", "urgent", "severe", "immediate", "pain", "critical"]
3
+ score = sum(1 for word in text.lower().split() if word in urgent_keywords)
4
+ return "High" if score > 1 else "Medium" if score == 1 else "Low"
vocca_ai/sentiment.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ # Load a better sentiment model
4
+ sentiment_model = pipeline("sentiment-analysis", model="cardiffnlp/twitter-xlm-roberta-base-sentiment")
5
+
6
+ def analyze_sentiment(text):
7
+ """
8
+ Uses a specialized sentiment model better suited for medical text.
9
+ """
10
+ result = sentiment_model(text)[0]["label"]
11
+
12
+ if result.lower() == "positive":
13
+ return "Positive"
14
+ elif result.lower() == "negative":
15
+ return "Concerned" # Replace "Negative" with a more medically appropriate term
16
+ return "Neutral"
17
+
18
+ # Example Usage
19
+ if __name__ == "__main__":
20
+ sample_text = "I've been feeling really weak and dizzy for the past few days."
21
+ print(f"Sentiment: {analyze_sentiment(sample_text)}")