mindspark121 commited on
Commit
f7e81db
·
verified ·
1 Parent(s): 23943df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -3,6 +3,7 @@ from pydantic import BaseModel
3
  from sentence_transformers import SentenceTransformer
4
  import faiss
5
  import pandas as pd
 
6
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
7
 
8
  app = FastAPI()
@@ -36,11 +37,31 @@ class SummaryRequest(BaseModel):
36
 
37
  @app.post("/get_questions")
38
  def get_recommended_questions(request: ChatRequest):
39
- """Retrieve the most relevant diagnostic questions."""
 
 
40
  input_embedding = embedding_model.encode([request.message], convert_to_numpy=True)
41
  distances, indices = question_index.search(input_embedding, 3)
 
 
42
  retrieved_questions = [questions_df["Questions"].iloc[i] for i in indices[0]]
43
- return {"questions": retrieved_questions}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  @app.post("/summarize_chat")
46
  def summarize_chat(request: SummaryRequest):
 
3
  from sentence_transformers import SentenceTransformer
4
  import faiss
5
  import pandas as pd
6
+ import random
7
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
8
 
9
  app = FastAPI()
 
37
 
38
  @app.post("/get_questions")
39
  def get_recommended_questions(request: ChatRequest):
40
+ """Retrieve the most relevant diagnostic questions with a conversational response."""
41
+
42
+ # Step 1: Encode the input message for FAISS search
43
  input_embedding = embedding_model.encode([request.message], convert_to_numpy=True)
44
  distances, indices = question_index.search(input_embedding, 3)
45
+
46
+ # Step 2: Retrieve the top 3 relevant questions
47
  retrieved_questions = [questions_df["Questions"].iloc[i] for i in indices[0]]
48
+
49
+ # Step 3: Define Dynamic Prompt Variations
50
+ empathetic_phrases = [
51
+ "I hear you, and I appreciate you sharing this. Let me ask:",
52
+ "That sounds challenging. Could you help me understand better by answering this:",
53
+ "I understand what you're going through. Here's something to think about:",
54
+ "Thank you for opening up. Let’s explore this further:",
55
+ "Your feelings are completely valid. Here's a question to help us understand more:"
56
+ ]
57
+
58
+ # Step 4: Generate Dynamic Responses
59
+ wrapped_responses = [
60
+ f"{random.choice(empathetic_phrases)} *{q}*"
61
+ for q in retrieved_questions
62
+ ]
63
+
64
+ return {"questions": wrapped_responses}
65
 
66
  @app.post("/summarize_chat")
67
  def summarize_chat(request: SummaryRequest):