Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import json
|
|
| 5 |
|
| 6 |
# Constants
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
|
| 8 |
-
MAX_NEW_TOKENS =
|
| 9 |
TEMPERATURE = 0.5
|
| 10 |
TOP_P = 0.9
|
| 11 |
|
|
@@ -18,10 +18,10 @@ HEADERS = {"Authorization": f"Bearer {api_token}"}
|
|
| 18 |
|
| 19 |
def analyze_figure_of_speech(text: str) -> str:
|
| 20 |
"""
|
| 21 |
-
Analyze the figures of speech in a given Bible
|
| 22 |
|
| 23 |
Args:
|
| 24 |
-
text (str): The Bible
|
| 25 |
|
| 26 |
Returns:
|
| 27 |
str: Analysis result formatted as text or error message.
|
|
@@ -29,6 +29,9 @@ def analyze_figure_of_speech(text: str) -> str:
|
|
| 29 |
if not text.strip():
|
| 30 |
return "Please enter a Bible verse or passage."
|
| 31 |
|
|
|
|
|
|
|
|
|
|
| 32 |
# Construct the prompt for the model
|
| 33 |
prompt = (
|
| 34 |
f"""<s>[INST] You are JR-Sacred Syntax, an expert biblical scholar specializing in Bible analysis.
|
|
@@ -39,6 +42,7 @@ def analyze_figure_of_speech(text: str) -> str:
|
|
| 39 |
- "definition": define the figure of speech you identified,
|
| 40 |
- "phrase": the exact phrase from the verse,
|
| 41 |
- "explanation": a brief explanation in the biblical context.
|
|
|
|
| 42 |
Bible Passage: "{text}"
|
| 43 |
[/INST] Figures: </s>"""
|
| 44 |
)
|
|
@@ -94,8 +98,8 @@ demo = gr.Interface(
|
|
| 94 |
fn=analyze_figure_of_speech,
|
| 95 |
inputs=gr.Textbox(
|
| 96 |
label="Enter Bible Verse(s) or Passage",
|
| 97 |
-
placeholder="e.g., '
|
| 98 |
-
lines=10
|
| 99 |
),
|
| 100 |
outputs=gr.Textbox(label="Figures of Speech Analysis"),
|
| 101 |
title="JR-Sacred Syntax: Bible Figures of Speech Detector",
|
|
|
|
| 5 |
|
| 6 |
# Constants
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
|
| 8 |
+
MAX_NEW_TOKENS = 1000 # Increased to handle longer inputs
|
| 9 |
TEMPERATURE = 0.5
|
| 10 |
TOP_P = 0.9
|
| 11 |
|
|
|
|
| 18 |
|
| 19 |
def analyze_figure_of_speech(text: str) -> str:
|
| 20 |
"""
|
| 21 |
+
Analyze the figures of speech in a given Bible passage using a Hugging Face model.
|
| 22 |
|
| 23 |
Args:
|
| 24 |
+
text (str): The Bible passage to analyze.
|
| 25 |
|
| 26 |
Returns:
|
| 27 |
str: Analysis result formatted as text or error message.
|
|
|
|
| 29 |
if not text.strip():
|
| 30 |
return "Please enter a Bible verse or passage."
|
| 31 |
|
| 32 |
+
# Split the input into individual verses
|
| 33 |
+
verses = text.splitlines()
|
| 34 |
+
|
| 35 |
# Construct the prompt for the model
|
| 36 |
prompt = (
|
| 37 |
f"""<s>[INST] You are JR-Sacred Syntax, an expert biblical scholar specializing in Bible analysis.
|
|
|
|
| 42 |
- "definition": define the figure of speech you identified,
|
| 43 |
- "phrase": the exact phrase from the verse,
|
| 44 |
- "explanation": a brief explanation in the biblical context.
|
| 45 |
+
Consider each verse individually and provide a detailed analysis.
|
| 46 |
Bible Passage: "{text}"
|
| 47 |
[/INST] Figures: </s>"""
|
| 48 |
)
|
|
|
|
| 98 |
fn=analyze_figure_of_speech,
|
| 99 |
inputs=gr.Textbox(
|
| 100 |
label="Enter Bible Verse(s) or Passage",
|
| 101 |
+
placeholder="e.g., 'In the beginning God created the heavens and the earth.' - Gen 1:1\n'And the earth was without form and void; and darkness was upon the face of the deep.' - Gen 1:2\n'And the Spirit of God moved upon the face of the waters.' - Gen 1:3",
|
| 102 |
+
lines=10
|
| 103 |
),
|
| 104 |
outputs=gr.Textbox(label="Figures of Speech Analysis"),
|
| 105 |
title="JR-Sacred Syntax: Bible Figures of Speech Detector",
|