Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,16 @@ import os
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Retrieve the API token from secrets
|
7 |
api_token = os.getenv("API_TOKEN")
|
@@ -12,9 +22,6 @@ if not api_token:
|
|
12 |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3" # Corrected URL
|
13 |
HEADERS = {"Authorization": f"Bearer {api_token}"}
|
14 |
|
15 |
-
def lookup_passage(passage):
|
16 |
-
# Placeholder implementation
|
17 |
-
return f"Text for {passage}"
|
18 |
|
19 |
def generate_exegesis(passage):
|
20 |
if not passage.strip():
|
@@ -27,12 +34,11 @@ def generate_exegesis(passage):
|
|
27 |
payload = {
|
28 |
"inputs": prompt,
|
29 |
}
|
30 |
-
|
31 |
try:
|
32 |
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
33 |
response.raise_for_status()
|
34 |
result = response.json()
|
35 |
-
|
36 |
|
37 |
if isinstance(result, list) and len(result) > 0:
|
38 |
generated_text = result[0].get("generated_text", "")
|
@@ -59,7 +65,7 @@ def ask_any_questions(question):
|
|
59 |
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
60 |
response.raise_for_status()
|
61 |
result = response.json()
|
62 |
-
|
63 |
|
64 |
if isinstance(result, list) and len(result) > 0:
|
65 |
answer_text = result[0].get("generated_text", "")
|
@@ -137,22 +143,22 @@ exegesis_demo = gr.Interface(
|
|
137 |
)
|
138 |
|
139 |
lookup_demo = gr.Interface(
|
140 |
-
fn=lookup_passage,
|
141 |
-
inputs=gr.Textbox(label="Lookup Bible Passage", placeholder="e.g., John 3:16"),
|
142 |
-
outputs=gr.Textbox(label="Passage Text"),
|
143 |
-
title="Bible Passage Lookup",
|
144 |
-
description="Enter a Bible passage to lookup its text."
|
145 |
-
)
|
146 |
-
|
147 |
-
commentary_demo = gr.Interface(
|
148 |
fn=ask_any_questions,
|
149 |
-
inputs=gr.Textbox(label="Ask
|
150 |
outputs=gr.Textbox(label="Answer"),
|
151 |
-
title="Bible
|
152 |
-
description="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
)
|
154 |
|
155 |
-
|
156 |
fn=keyword_search,
|
157 |
inputs=gr.Textbox(label="Keyword Search", placeholder="e.g., love"),
|
158 |
outputs=gr.Textbox(label="Search Results"),
|
@@ -161,10 +167,10 @@ search_demo = gr.Interface(
|
|
161 |
)
|
162 |
|
163 |
# Combine all interfaces into one app
|
164 |
-
|
165 |
-
[exegesis_demo, lookup_demo,
|
166 |
-
["Exegesis", "
|
167 |
)
|
168 |
|
169 |
if __name__ == "__main__":
|
170 |
-
|
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import json
|
5 |
+
# import logging
|
6 |
+
import logging
|
7 |
+
# Retrieve the API token from secrets
|
8 |
+
api_token = os.getenv("API_TOKEN")
|
9 |
+
if not api_token:
|
10 |
+
raise ValueError("API token not found. Make sure 'API_TOKEN' is set in the Secrets.")
|
11 |
+
|
12 |
+
# Configure logging
|
13 |
+
logging.basicConfig(level=logging.INFO)
|
14 |
+
logger = logging.getLogger(__name__)
|
15 |
|
16 |
# Retrieve the API token from secrets
|
17 |
api_token = os.getenv("API_TOKEN")
|
|
|
22 |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3" # Corrected URL
|
23 |
HEADERS = {"Authorization": f"Bearer {api_token}"}
|
24 |
|
|
|
|
|
|
|
25 |
|
26 |
def generate_exegesis(passage):
|
27 |
if not passage.strip():
|
|
|
34 |
payload = {
|
35 |
"inputs": prompt,
|
36 |
}
|
|
|
37 |
try:
|
38 |
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
39 |
response.raise_for_status()
|
40 |
result = response.json()
|
41 |
+
logger.debug("Full API Response: %s", json.dumps(result, indent=4)) # Debug output
|
42 |
|
43 |
if isinstance(result, list) and len(result) > 0:
|
44 |
generated_text = result[0].get("generated_text", "")
|
|
|
65 |
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
66 |
response.raise_for_status()
|
67 |
result = response.json()
|
68 |
+
logger.debug("Full API Response: %s", json.dumps(result, indent=4)) # Debug output
|
69 |
|
70 |
if isinstance(result, list) and len(result) > 0:
|
71 |
answer_text = result[0].get("generated_text", "")
|
|
|
143 |
)
|
144 |
|
145 |
lookup_demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
fn=ask_any_questions,
|
147 |
+
inputs=gr.Textbox(label="Ask Any Bible Question", placeholder="e.g., What does John 3:16 mean?"),
|
148 |
outputs=gr.Textbox(label="Answer"),
|
149 |
+
title="Bible Question Answering",
|
150 |
+
description="Enter a Bible-related question to receive a detailed answer."
|
151 |
+
)
|
152 |
+
|
153 |
+
sermon_demo = gr.Interface(
|
154 |
+
fn=generate_sermon,
|
155 |
+
inputs=gr.Textbox(label="Generate Sermon", placeholder="e.g., Faith"),
|
156 |
+
outputs=gr.Textbox(label="Sermon"),
|
157 |
+
title="Bible Sermon Generator",
|
158 |
+
description="Enter a topic to generate a detailed sermon."
|
159 |
)
|
160 |
|
161 |
+
keyword_search_demo = gr.Interface(
|
162 |
fn=keyword_search,
|
163 |
inputs=gr.Textbox(label="Keyword Search", placeholder="e.g., love"),
|
164 |
outputs=gr.Textbox(label="Search Results"),
|
|
|
167 |
)
|
168 |
|
169 |
# Combine all interfaces into one app
|
170 |
+
bible_app = gr.TabbedInterface(
|
171 |
+
[exegesis_demo, lookup_demo, sermon_demo, keyword_search_demo],
|
172 |
+
["Exegesis", "Question Answering", "Sermon Generator", "Keyword Search"]
|
173 |
)
|
174 |
|
175 |
if __name__ == "__main__":
|
176 |
+
bible_app.launch()
|