Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,16 @@
|
|
1 |
import os
|
2 |
from transformers import pipeline
|
3 |
import gradio as gr
|
4 |
-
import requests
|
5 |
-
import json
|
6 |
import logging
|
|
|
|
|
|
|
7 |
|
8 |
# Retrieve the API token from secrets
|
9 |
api_token = os.getenv("API_TOKEN")
|
10 |
if not api_token:
|
11 |
raise ValueError("API token not found. Make sure 'API_TOKEN' is set in the Secrets.")
|
12 |
|
13 |
-
# Define API constants
|
14 |
-
API_URL = "https://api-inference.huggingface.co/models/google/gemma-2b"
|
15 |
-
HEADERS = {
|
16 |
-
"Authorization": f"Bearer {api_token}",
|
17 |
-
"Content-Type": "application/json"
|
18 |
-
}
|
19 |
-
|
20 |
# Configure logging
|
21 |
logging.basicConfig(level=logging.INFO)
|
22 |
logger = logging.getLogger(__name__)
|
@@ -27,13 +21,8 @@ pipe = pipeline("text-generation", model="google/gemma-2b")
|
|
27 |
def generate_exegesis(passage):
|
28 |
if not passage.strip():
|
29 |
return "Please enter a Bible passage."
|
30 |
-
|
31 |
-
prompt = f"""<s>[INST] You are a professional Bible Scholar. Provide a detailed exegesis of the following biblical verse, including:
|
32 |
-
The original Greek text and transliteration with word-by-word analysis and meanings, historical and cultural context, and theological significance for:
|
33 |
-
{passage} [/INST] Exegesis:</s>"""
|
34 |
-
|
35 |
try:
|
36 |
-
# Use pipeline instead of API call
|
37 |
result = pipe(prompt, max_length=1000, num_return_sequences=1)[0]
|
38 |
generated_text = result['generated_text']
|
39 |
marker = "Exegesis:"
|
@@ -47,11 +36,7 @@ def generate_exegesis(passage):
|
|
47 |
def ask_any_questions(question):
|
48 |
if not question.strip():
|
49 |
return "Please enter a question."
|
50 |
-
|
51 |
-
prompt = f"""<s>[INST] You are a professional Bible Scholar. Provide a detailed answer to the following question, including:
|
52 |
-
Relevant Bible verses, their explanations, and theological significance for:
|
53 |
-
{question} [/INST] Answer:</s>"""
|
54 |
-
|
55 |
try:
|
56 |
result = pipe(prompt, max_length=1000, num_return_sequences=1)[0]
|
57 |
answer_text = result['generated_text']
|
@@ -66,10 +51,7 @@ def ask_any_questions(question):
|
|
66 |
def generate_sermon(topic):
|
67 |
if not topic.strip():
|
68 |
return "Please enter a topic."
|
69 |
-
|
70 |
-
prompt = f"""<s>[INST] You are a highly knowledgeable Bible Scholar and Pastor...
|
71 |
-
{topic} [/INST] Sermon:</s>"""
|
72 |
-
|
73 |
try:
|
74 |
result = pipe(prompt, max_length=2000, num_return_sequences=1)[0]
|
75 |
sermon_text = result['generated_text']
|
@@ -84,9 +66,7 @@ def generate_sermon(topic):
|
|
84 |
def keyword_search(keyword):
|
85 |
if not keyword.strip():
|
86 |
return "Please enter a keyword."
|
87 |
-
|
88 |
prompt = f"""<s>[INST] You are a Bible Scholar. Find relevant Bible passages containing the keyword: {keyword} [/INST] Search Results:</s>"""
|
89 |
-
|
90 |
try:
|
91 |
result = pipe(prompt, max_length=1000, num_return_sequences=1)[0]
|
92 |
search_results = result['generated_text']
|
@@ -104,38 +84,33 @@ exegesis_demo = gr.Interface(
|
|
104 |
inputs=gr.Textbox(label="Enter Bible Passage for Exegesis", placeholder="e.g., John 3:16"),
|
105 |
outputs=gr.Textbox(label="Exegesis Commentary"),
|
106 |
title="JR Study Bible",
|
107 |
-
description="Enter a Bible passage to receive insightful exegesis commentary."
|
108 |
-
)
|
109 |
|
110 |
lookup_demo = gr.Interface(
|
111 |
fn=ask_any_questions,
|
112 |
inputs=gr.Textbox(label="Ask Any Bible Question", placeholder="e.g., What does John 3:16 mean?"),
|
113 |
outputs=gr.Textbox(label="Answer"),
|
114 |
title="Bible Question Answering",
|
115 |
-
description="Enter a Bible-related question to receive a detailed answer."
|
116 |
-
)
|
117 |
|
118 |
sermon_demo = gr.Interface(
|
119 |
fn=generate_sermon,
|
120 |
inputs=gr.Textbox(label="Generate Sermon", placeholder="e.g., Faith"),
|
121 |
outputs=gr.Textbox(label="Sermon"),
|
122 |
title="Bible Sermon Generator",
|
123 |
-
description="Enter a topic to generate a detailed sermon."
|
124 |
-
)
|
125 |
|
126 |
keyword_search_demo = gr.Interface(
|
127 |
fn=keyword_search,
|
128 |
inputs=gr.Textbox(label="Keyword Search", placeholder="e.g., love"),
|
129 |
outputs=gr.Textbox(label="Search Results"),
|
130 |
title="Bible Keyword Search",
|
131 |
-
description="Enter a keyword to search in the Bible."
|
132 |
-
)
|
133 |
|
134 |
# Combine all interfaces into one app
|
135 |
bible_app = gr.TabbedInterface(
|
136 |
[exegesis_demo, lookup_demo, sermon_demo, keyword_search_demo],
|
137 |
-
["Exegesis", "Question Answering", "Sermon Generator", "Keyword Search"]
|
138 |
-
)
|
139 |
|
140 |
if __name__ == "__main__":
|
141 |
-
bible_app.launch()
|
|
|
1 |
import os
|
2 |
from transformers import pipeline
|
3 |
import gradio as gr
|
|
|
|
|
4 |
import logging
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
|
7 |
+
load_dotenv() # Load environment variables from .env file
|
8 |
|
9 |
# Retrieve the API token from secrets
|
10 |
api_token = os.getenv("API_TOKEN")
|
11 |
if not api_token:
|
12 |
raise ValueError("API token not found. Make sure 'API_TOKEN' is set in the Secrets.")
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# Configure logging
|
15 |
logging.basicConfig(level=logging.INFO)
|
16 |
logger = logging.getLogger(__name__)
|
|
|
21 |
def generate_exegesis(passage):
|
22 |
if not passage.strip():
|
23 |
return "Please enter a Bible passage."
|
24 |
+
prompt = f"""<s>[INST] You are a professional Bible Scholar. Provide a detailed exegesis of the following biblical verse, including: The original Greek text and transliteration with word-by-word analysis and meanings, historical and cultural context, and theological significance for: {passage} [/INST] Exegesis:</s>"""
|
|
|
|
|
|
|
|
|
25 |
try:
|
|
|
26 |
result = pipe(prompt, max_length=1000, num_return_sequences=1)[0]
|
27 |
generated_text = result['generated_text']
|
28 |
marker = "Exegesis:"
|
|
|
36 |
def ask_any_questions(question):
|
37 |
if not question.strip():
|
38 |
return "Please enter a question."
|
39 |
+
prompt = f"""<s>[INST] You are a professional Bible Scholar. Provide a detailed answer to the following question, including: Relevant Bible verses, their explanations, and theological significance for: {question} [/INST] Answer:</s>"""
|
|
|
|
|
|
|
|
|
40 |
try:
|
41 |
result = pipe(prompt, max_length=1000, num_return_sequences=1)[0]
|
42 |
answer_text = result['generated_text']
|
|
|
51 |
def generate_sermon(topic):
|
52 |
if not topic.strip():
|
53 |
return "Please enter a topic."
|
54 |
+
prompt = f"""<s>[INST] You are a highly knowledgeable Bible Scholar and Pastor. Generate a detailed sermon on the following topic: {topic}. Include relevant Bible verses and theological insights. [/INST] Sermon:</s>"""
|
|
|
|
|
|
|
55 |
try:
|
56 |
result = pipe(prompt, max_length=2000, num_return_sequences=1)[0]
|
57 |
sermon_text = result['generated_text']
|
|
|
66 |
def keyword_search(keyword):
|
67 |
if not keyword.strip():
|
68 |
return "Please enter a keyword."
|
|
|
69 |
prompt = f"""<s>[INST] You are a Bible Scholar. Find relevant Bible passages containing the keyword: {keyword} [/INST] Search Results:</s>"""
|
|
|
70 |
try:
|
71 |
result = pipe(prompt, max_length=1000, num_return_sequences=1)[0]
|
72 |
search_results = result['generated_text']
|
|
|
84 |
inputs=gr.Textbox(label="Enter Bible Passage for Exegesis", placeholder="e.g., John 3:16"),
|
85 |
outputs=gr.Textbox(label="Exegesis Commentary"),
|
86 |
title="JR Study Bible",
|
87 |
+
description="Enter a Bible passage to receive insightful exegesis commentary.")
|
|
|
88 |
|
89 |
lookup_demo = gr.Interface(
|
90 |
fn=ask_any_questions,
|
91 |
inputs=gr.Textbox(label="Ask Any Bible Question", placeholder="e.g., What does John 3:16 mean?"),
|
92 |
outputs=gr.Textbox(label="Answer"),
|
93 |
title="Bible Question Answering",
|
94 |
+
description="Enter a Bible-related question to receive a detailed answer.")
|
|
|
95 |
|
96 |
sermon_demo = gr.Interface(
|
97 |
fn=generate_sermon,
|
98 |
inputs=gr.Textbox(label="Generate Sermon", placeholder="e.g., Faith"),
|
99 |
outputs=gr.Textbox(label="Sermon"),
|
100 |
title="Bible Sermon Generator",
|
101 |
+
description="Enter a topic to generate a detailed sermon.")
|
|
|
102 |
|
103 |
keyword_search_demo = gr.Interface(
|
104 |
fn=keyword_search,
|
105 |
inputs=gr.Textbox(label="Keyword Search", placeholder="e.g., love"),
|
106 |
outputs=gr.Textbox(label="Search Results"),
|
107 |
title="Bible Keyword Search",
|
108 |
+
description="Enter a keyword to search in the Bible.")
|
|
|
109 |
|
110 |
# Combine all interfaces into one app
|
111 |
bible_app = gr.TabbedInterface(
|
112 |
[exegesis_demo, lookup_demo, sermon_demo, keyword_search_demo],
|
113 |
+
["Exegesis", "Question Answering", "Sermon Generator", "Keyword Search"])
|
|
|
114 |
|
115 |
if __name__ == "__main__":
|
116 |
+
bible_app.launch()
|