Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,20 +19,44 @@ HEADERS = {"Authorization": f"Bearer {api_token}"}
|
|
19 |
|
20 |
def generate_exegesis(passage):
|
21 |
if not passage.strip():
|
22 |
-
return "Please enter a Bible passage."
|
23 |
|
24 |
-
prompt =
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
payload = {
|
29 |
"inputs": prompt,
|
30 |
}
|
31 |
try:
|
32 |
-
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
33 |
response.raise_for_status()
|
34 |
result = response.json()
|
35 |
-
logger.debug("
|
36 |
|
37 |
if isinstance(result, list) and len(result) > 0:
|
38 |
generated_text = result[0].get("generated_text", "")
|
@@ -43,22 +67,40 @@ def generate_exegesis(passage):
|
|
43 |
else:
|
44 |
return "Error: Unexpected response format."
|
45 |
except requests.exceptions.RequestException as e:
|
46 |
-
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
payload = {
|
54 |
"inputs": prompt,
|
55 |
}
|
56 |
|
57 |
try:
|
58 |
-
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
59 |
response.raise_for_status()
|
60 |
result = response.json()
|
61 |
-
|
|
|
62 |
|
63 |
if isinstance(result, list) and len(result) > 0:
|
64 |
answer_text = result[0].get("generated_text", "")
|
@@ -69,22 +111,83 @@ def ask_any_questions(question):
|
|
69 |
else:
|
70 |
return "Error: Unexpected response format."
|
71 |
except requests.exceptions.RequestException as e:
|
72 |
-
|
|
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
payload = {
|
80 |
"inputs": prompt,
|
81 |
}
|
82 |
|
83 |
try:
|
84 |
-
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
85 |
response.raise_for_status()
|
86 |
result = response.json()
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
if isinstance(result, list) and len(result) > 0:
|
90 |
sermon_text = result[0].get("generated_text", "")
|
@@ -98,10 +201,22 @@ def generate_sermon(topic):
|
|
98 |
return f"API Error: {e}"
|
99 |
|
100 |
def keyword_search(keyword):
|
101 |
-
prompt =
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
payload = {
|
106 |
"inputs": prompt,
|
107 |
}
|
@@ -133,7 +248,7 @@ exegesis_demo = gr.Interface(
|
|
133 |
)
|
134 |
|
135 |
lookup_demo = gr.Interface(
|
136 |
-
fn=
|
137 |
inputs=gr.Textbox(label="Ask Any Bible Question", placeholder="e.g., What does John 3:16 mean?"),
|
138 |
outputs=gr.Textbox(label="Answer"),
|
139 |
title="Bible Question Answering",
|
|
|
19 |
|
20 |
def generate_exegesis(passage):
|
21 |
if not passage.strip():
|
22 |
+
return "Please enter a valid Bible passage."
|
23 |
|
24 |
+
prompt = (
|
25 |
+
f"""<s>[INST] You are a highly knowledgeable **Bible Scholar and Theologian**, """
|
26 |
+
f"""specializing in **biblical exegesis, original languages, and historical context**.
|
27 |
+
|
28 |
+
Perform a **detailed exegesis** of the following biblical passage:
|
29 |
+
**"{passage}"**
|
30 |
+
|
31 |
+
Your response should include:
|
32 |
+
|
33 |
+
1. **Original Language Analysis** – Provide the **Greek (NT) or Hebrew (OT) text**, """
|
34 |
+
f"""including **transliteration** and word-by-word breakdown.
|
35 |
+
2. **Lexical Insights** – Explain key words using sources like **Strong’s Concordance, """
|
36 |
+
f"""Thayer’s Lexicon, and BDB**.
|
37 |
+
3. **Historical & Cultural Context** – Discuss the passage’s background, audience, and setting.
|
38 |
+
4. **Literary & Thematic Analysis** – Examine the passage’s **grammatical structure, literary form, """
|
39 |
+
f"""and theological themes**.
|
40 |
+
5. **Theological Significance** – Explain how the passage contributes to **Christian doctrine** """
|
41 |
+
f"""and biblical theology.
|
42 |
+
6. **Cross-References** – List related biblical passages that provide deeper understanding.
|
43 |
+
7. **Interpretative Views** – Present differing theological interpretations if applicable.
|
44 |
+
8. **Practical Application** – Explain how this passage applies to faith and Christian living.
|
45 |
+
|
46 |
+
Your response should be **deeply analytical, theologically sound, and easy to understand**, """
|
47 |
+
f"""drawing from **scholarly sources and traditional interpretations**. [/INST]
|
48 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload, timeout=10)
|
49 |
+
### Exegesis:</s>"""
|
50 |
+
)
|
51 |
|
52 |
payload = {
|
53 |
"inputs": prompt,
|
54 |
}
|
55 |
try:
|
56 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload, timeout=10)
|
57 |
response.raise_for_status()
|
58 |
result = response.json()
|
59 |
+
logger.debug("API Response received successfully.")
|
60 |
|
61 |
if isinstance(result, list) and len(result) > 0:
|
62 |
generated_text = result[0].get("generated_text", "")
|
|
|
67 |
else:
|
68 |
return "Error: Unexpected response format."
|
69 |
except requests.exceptions.RequestException as e:
|
70 |
+
logger.error(f"API Error: {e}")
|
71 |
+
return "An error occurred while processing your request. Please try again later."
|
72 |
|
73 |
+
prompt = (
|
74 |
+
f"""<s>[INST] You are a highly knowledgeable **Bible Scholar and Theologian**, """
|
75 |
+
f"""specializing in biblical exegesis, historical context, and doctrinal analysis.
|
76 |
+
|
77 |
+
Provide a **detailed and well-researched answer** to the following question:
|
78 |
+
**"{question}"**
|
79 |
+
|
80 |
+
Your response should include:
|
81 |
+
|
82 |
+
1. **Relevant Bible Passages** – Cite key Scriptures that address the question.
|
83 |
+
2. **Exegesis & Context** – Analyze the historical, cultural, and linguistic background of these verses.
|
84 |
+
3. **Theological Insights** – Explain the doctrinal significance and its relevance to Christian faith.
|
85 |
+
4. **Different Interpretations (if applicable)** – Present various theological perspectives if there are differing views.
|
86 |
+
5. **Practical Application** – Relate the answer to real-life faith and Christian living.
|
87 |
+
|
88 |
+
Your response should be **scholarly yet easy to understand**, maintaining biblical accuracy while making it applicable for personal growth. [/INST]
|
89 |
+
|
90 |
+
### Answer:</s>"""
|
91 |
+
)
|
92 |
+
### Answer:</s>"""
|
93 |
|
94 |
payload = {
|
95 |
"inputs": prompt,
|
96 |
}
|
97 |
|
98 |
try:
|
99 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload, timeout=10)
|
100 |
response.raise_for_status()
|
101 |
result = response.json()
|
102 |
+
sanitized_result = {k: (v if k != "generated_text" else "REDACTED") for k, v in result[0].items()}
|
103 |
+
logger.debug("Sanitized API Response: %s", json.dumps(sanitized_result, indent=4))
|
104 |
|
105 |
if isinstance(result, list) and len(result) > 0:
|
106 |
answer_text = result[0].get("generated_text", "")
|
|
|
111 |
else:
|
112 |
return "Error: Unexpected response format."
|
113 |
except requests.exceptions.RequestException as e:
|
114 |
+
logger.error(f"API Error: {e}")
|
115 |
+
return "An error occurred while processing your request. Please try again later."
|
116 |
|
117 |
+
prompt = (
|
118 |
+
f"""<s>[INST] You are a highly knowledgeable **Bible Scholar and Pastor**, well-versed in biblical exegesis, theology, and homiletics.
|
119 |
+
|
120 |
+
Prepare a **detailed and compelling sermon** on the following topic:
|
121 |
+
**"{topic}"**
|
122 |
+
|
123 |
+
Your sermon should include:
|
124 |
+
|
125 |
+
1. **Title & Theme** – Provide a clear, impactful sermon title and theme.
|
126 |
+
2. **Key Bible Passages** – Cite relevant Scriptures (OT & NT) and explain their meaning.
|
127 |
+
3. **Exegesis & Context** – Analyze the historical, cultural, and linguistic background of key verses.
|
128 |
+
4. **Theological Insights** – Explain the doctrinal significance and how it aligns with biblical teaching.
|
129 |
+
5. **Illustrations & Real-Life Applications** – Include relatable examples, stories, or analogies to make the message practical.
|
130 |
+
6. **Call to Action** – End with a strong conclusion, a challenge for personal transformation, and a prayer if applicable.
|
131 |
+
|
132 |
+
Your sermon should be **well-structured, theologically rich, engaging, and applicable to daily Christian living.** Use a pastoral yet authoritative tone. [/INST]
|
133 |
+
|
134 |
+
### Sermon:</s>"""
|
135 |
+
)
|
136 |
+
### Sermon:</s>"""
|
137 |
|
138 |
payload = {
|
139 |
"inputs": prompt,
|
140 |
}
|
141 |
|
142 |
try:
|
143 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload, timeout=10)
|
144 |
response.raise_for_status()
|
145 |
result = response.json()
|
146 |
+
sanitized_result = {k: (v if k != "generated_text" else "REDACTED") for k, v in result[0].items()}
|
147 |
+
logger.debug("Sanitized API Response: %s", json.dumps(sanitized_result, indent=4))
|
148 |
+
|
149 |
+
if isinstance(result, list) and len(result) > 0:
|
150 |
+
sermon_text = result[0].get("generated_text", "")
|
151 |
+
marker = "Sermon:"
|
152 |
+
if marker in sermon_text:
|
153 |
+
sermon_text = sermon_text.split(marker, 1)[1].strip()
|
154 |
+
return sermon_text or "Error: No response from model."
|
155 |
+
else:
|
156 |
+
return "Error: Unexpected response format."
|
157 |
+
except requests.exceptions.RequestException as e:
|
158 |
+
logger.error(f"API Error: {e}")
|
159 |
+
return "An error occurred while processing your request. Please try again later."
|
160 |
+
|
161 |
+
def generate_sermon(topic):
|
162 |
+
prompt = (
|
163 |
+
f"""<s>[INST] You are a highly knowledgeable **Bible Scholar and Pastor**, well-versed in biblical exegesis, theology, and homiletics.
|
164 |
+
|
165 |
+
Prepare a **detailed and compelling sermon** on the following topic:
|
166 |
+
**"{topic}"**
|
167 |
+
|
168 |
+
Your sermon should include:
|
169 |
+
|
170 |
+
1. **Title & Theme** – Provide a clear, impactful sermon title and theme.
|
171 |
+
2. **Key Bible Passages** – Cite relevant Scriptures (OT & NT) and explain their meaning.
|
172 |
+
3. **Exegesis & Context** – Analyze the historical, cultural, and linguistic background of key verses.
|
173 |
+
4. **Theological Insights** – Explain the doctrinal significance and how it aligns with biblical teaching.
|
174 |
+
5. **Illustrations & Real-Life Applications** – Include relatable examples, stories, or analogies to make the message practical.
|
175 |
+
6. **Call to Action** – End with a strong conclusion, a challenge for personal transformation, and a prayer if applicable.
|
176 |
+
|
177 |
+
Your sermon should be **well-structured, theologically rich, engaging, and applicable to daily Christian living.** Use a pastoral yet authoritative tone. [/INST]
|
178 |
+
|
179 |
+
### Sermon:</s>"""
|
180 |
+
)
|
181 |
+
payload = {
|
182 |
+
"inputs": prompt,
|
183 |
+
}
|
184 |
+
|
185 |
+
try:
|
186 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload, timeout=10)
|
187 |
+
response.raise_for_status()
|
188 |
+
result = response.json()
|
189 |
+
sanitized_result = {k: (v if k != "generated_text" else "REDACTED") for k, v in result[0].items()}
|
190 |
+
logger.debug("Sanitized API Response: %s", json.dumps(sanitized_result, indent=4))
|
191 |
|
192 |
if isinstance(result, list) and len(result) > 0:
|
193 |
sermon_text = result[0].get("generated_text", "")
|
|
|
201 |
return f"API Error: {e}"
|
202 |
|
203 |
def keyword_search(keyword):
|
204 |
+
prompt = (
|
205 |
+
f"""<s>[INST] You are a highly knowledgeable and professional Bible scholar with expertise in biblical languages, hermeneutics, and textual criticism.
|
206 |
+
|
207 |
+
Search for the keyword **"{keyword}"** in the Bible and provide a comprehensive analysis, including:
|
208 |
+
|
209 |
+
1. **Relevant Passages** – Cite verses from the Old and New Testaments where this keyword appears.
|
210 |
+
2. **Original Language Analysis** – Provide the Hebrew (OT) or Greek (NT) word, its **Strong’s Concordance number**, transliteration, and translation.
|
211 |
+
3. **Lexical Definition** – Offer definitions from reputable sources like **Brown-Driver-Briggs (BDB), Thayer’s Greek Lexicon, or HALOT**.
|
212 |
+
4. **Contextual Analysis** – Explain how the word is used within different passages, including historical and cultural insights.
|
213 |
+
5. **Theological Implications** – Discuss the theological significance and how the term contributes to biblical doctrine.
|
214 |
+
6. **Cross-References** – List related biblical passages and concepts.
|
215 |
+
7. **Exegesis** – Provide a well-reasoned exegesis of key verses, considering grammatical structure, literary context, and interpretative traditions.
|
216 |
+
|
217 |
+
Be precise, scholarly, and include citations when necessary. [/INST]
|
218 |
+
Search Results:</s>"""
|
219 |
+
)
|
220 |
payload = {
|
221 |
"inputs": prompt,
|
222 |
}
|
|
|
248 |
)
|
249 |
|
250 |
lookup_demo = gr.Interface(
|
251 |
+
fn=generate_exegesis,
|
252 |
inputs=gr.Textbox(label="Ask Any Bible Question", placeholder="e.g., What does John 3:16 mean?"),
|
253 |
outputs=gr.Textbox(label="Answer"),
|
254 |
title="Bible Question Answering",
|