amasha03 commited on
Commit
330bbb1
·
verified ·
1 Parent(s): f59d609

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -21,7 +21,7 @@ def main_orchestrator(audio_input, text_input, history):
21
  if history is None:
22
  history = []
23
 
24
- # 1. EMOTION LOGIC
25
  emotion = "Neutral"
26
  try:
27
  if audio_input:
@@ -31,34 +31,46 @@ def main_orchestrator(audio_input, text_input, history):
31
  except:
32
  emotion = "Neutral"
33
 
34
- # 2. LLM LOGIC (Strict format for the sub-space API)
 
35
  api_history = []
36
  for u, b in history:
37
- api_history.append({"role": "user", "content": [{"type": "text", "text": str(u)}]})
38
- api_history.append({"role": "assistant", "content": [{"type": "text", "text": str(b)}]})
 
 
 
 
 
 
39
 
40
- prompt = f"Context: User is {emotion}. Message: {text_input}"
41
-
 
 
 
 
 
 
42
  try:
43
- # Calling your sub-space
44
  response = llm_english.predict(
45
- message={"role": "user", "content": [{"type": "text", "text": prompt}]},
46
  history=api_history,
47
  api_name="/chat"
48
  )
49
  except Exception as e:
50
  response = f"LLM Error: {str(e)}"
51
 
52
- # 3. TTS LOGIC
53
  audio_res = None
54
  try:
55
- if tts_client:
56
  audio_res = tts_client.predict(str(response), api_name="/predict")
57
  except:
58
  audio_res = None
59
 
60
- # 4. UPDATE HISTORY
61
- # Simple list format [[user, bot]] is compatible with ALL Gradio versions
62
  history.append([text_input, response])
63
  return history, audio_res
64
 
 
21
  if history is None:
22
  history = []
23
 
24
+ # 1. EMOTION LOGIC (Keeping your current logic)
25
  emotion = "Neutral"
26
  try:
27
  if audio_input:
 
31
  except:
32
  emotion = "Neutral"
33
 
34
+ # 2. THE "STRICT" MESSAGE FIX
35
+ # We must turn history into a LIST of DICTIONARIES where 'content' is ALSO A LIST
36
  api_history = []
37
  for u, b in history:
38
+ api_history.append({
39
+ "role": "user",
40
+ "content": [{"type": "text", "text": str(u)}] # <--- This list is the fix!
41
+ })
42
+ api_history.append({
43
+ "role": "assistant",
44
+ "content": [{"type": "text", "text": str(b)}]
45
+ })
46
 
47
+ # 3. THE "STRICT" CURRENT MESSAGE FIX
48
+ bundled_text = f"Context: User is {emotion}. Message: {text_input}"
49
+ current_message = {
50
+ "role": "user",
51
+ "content": [{"type": "text", "text": bundled_text}] # <--- Nested list here too
52
+ }
53
+
54
+ # 4. CALL LLM
55
  try:
56
+ # Now the data matches the 'ChatMessage' object exactly
57
  response = llm_english.predict(
58
+ message=current_message,
59
  history=api_history,
60
  api_name="/chat"
61
  )
62
  except Exception as e:
63
  response = f"LLM Error: {str(e)}"
64
 
65
+ # 5. TTS & RETURN
66
  audio_res = None
67
  try:
68
+ if tts_client and response:
69
  audio_res = tts_client.predict(str(response), api_name="/predict")
70
  except:
71
  audio_res = None
72
 
73
+ # For the UI Chatbot, we keep it simple so it doesn't crash older versions
 
74
  history.append([text_input, response])
75
  return history, audio_res
76