ManishThota commited on
Commit
032d6c3
1 Parent(s): 5cbf359

Update src/text_processor.py

Browse files
Files changed (1) hide show
  1. src/text_processor.py +14 -2
src/text_processor.py CHANGED
@@ -62,7 +62,15 @@ def generate_logic(llm_output: str) -> str:
62
  # Extract JSON from the generated text
63
  start_index = generated_text.find('{')
64
  end_index = generated_text.rfind('}') + 1
65
- return generated_text[start_index:end_index]
 
 
 
 
 
 
 
 
66
 
67
  # Pydantic model for structured output
68
  class VideoAnalysis(BaseModel):
@@ -73,7 +81,11 @@ class VideoAnalysis(BaseModel):
73
 
74
  @classmethod
75
  def from_llm_output(cls, generated_logic: str) -> 'VideoAnalysis':
76
- logic_dict = json.loads(generated_logic)
 
 
 
 
77
  return cls(
78
  screen_interaction_yes=logic_dict.get("Screen.interaction_yes", 0),
79
  hands_free=logic_dict.get("Hands.free", 0),
 
62
  # Extract JSON from the generated text
63
  start_index = generated_text.find('{')
64
  end_index = generated_text.rfind('}') + 1
65
+ json_str = generated_text[start_index:end_index]
66
+
67
+ # Log the generated JSON string for debugging
68
+ print(f"Generated JSON: {json_str}")
69
+
70
+ if not json_str.strip():
71
+ raise ValueError("Generated logic is empty or invalid JSON")
72
+
73
+ return json_str
74
 
75
  # Pydantic model for structured output
76
  class VideoAnalysis(BaseModel):
 
81
 
82
  @classmethod
83
  def from_llm_output(cls, generated_logic: str) -> 'VideoAnalysis':
84
+ try:
85
+ logic_dict = json.loads(generated_logic)
86
+ except json.JSONDecodeError as e:
87
+ raise ValueError(f"Error decoding JSON: {e}") from e
88
+
89
  return cls(
90
  screen_interaction_yes=logic_dict.get("Screen.interaction_yes", 0),
91
  hands_free=logic_dict.get("Hands.free", 0),