Josebert commited on
Commit
209b85c
·
verified ·
1 Parent(s): 790978b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -18,12 +18,12 @@ def analyze_figure_of_speech(verse):
18
 
19
  # Construct a prompt to instruct the model to analyze figures of speech in the verse.
20
  prompt = f"""<s>[INST] You are JR-Sacred Syntax, an expert biblical scholar specializing in Bible analysis.
21
- Analyze the following Bible verse to identify any figures of speech (e.g., Metaphor, Synecdoche, Hyperbole, Simile, Paradox and other ones).
22
- Return your answer as a JSON array where each element includes:
23
- - "verses": give the Bible verse in NJV,
24
  - "figure": the type of figure of speech,
25
  - "phrase": the exact phrase from the verse,
26
- - "explanation": a brief explanation in biblical context.
27
  Bible Verse: "{verse}"
28
  [/INST] Figures: </s>"""
29
 
@@ -42,10 +42,13 @@ def analyze_figure_of_speech(verse):
42
  try:
43
  output_json = json.loads(generated_text)
44
  if isinstance(output_json, list): # Ensure it's a list
45
- # Print only values, not keys
46
- return "\n\n".join("\n".join(str(value) for value in item.values() if value) for item in output_json)
 
 
 
47
  else:
48
- return json.dumps(output_json, indent=2)
49
  except json.JSONDecodeError:
50
  return generated_text
51
  else:
 
18
 
19
  # Construct a prompt to instruct the model to analyze figures of speech in the verse.
20
  prompt = f"""<s>[INST] You are JR-Sacred Syntax, an expert biblical scholar specializing in Bible analysis.
21
+ Analyze the following Bible verse to identify any figures of speech (e.g., Metaphor, Synecdoche, Hyperbole, Simile, Paradox, and others).
22
+ Return your answer as a JSON array where each element includes:
23
+ - "verses": the Bible verse in NJV,
24
  - "figure": the type of figure of speech,
25
  - "phrase": the exact phrase from the verse,
26
+ - "explanation": a brief explanation in the biblical context.
27
  Bible Verse: "{verse}"
28
  [/INST] Figures: </s>"""
29
 
 
42
  try:
43
  output_json = json.loads(generated_text)
44
  if isinstance(output_json, list): # Ensure it's a list
45
+ # Extract and format only the values, skipping keys
46
+ formatted_output = "\n\n".join(
47
+ "\n".join(str(value) for key, value in item.items() if value) for item in output_json
48
+ )
49
+ return formatted_output
50
  else:
51
+ return json.dumps(output_json, indent=2) # Fallback to JSON formatting
52
  except json.JSONDecodeError:
53
  return generated_text
54
  else: