Josebert commited on
Commit
59b0b83
·
verified ·
1 Parent(s): 2eb6cd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -51
app.py CHANGED
@@ -1,51 +1,52 @@
1
- import os
2
- import gradio as gr
3
- import requests
4
-
5
- # Retrieve the API token from environment variables
6
- API_TOKEN = os.getenv("API_TOKEN")
7
- if not API_TOKEN:
8
- raise ValueError("API token not found. Please set the API_TOKEN environment variable.")
9
-
10
- API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-3.2-1B-Instruct"
11
- HEADERS = {"Authorization": f"Bearer {API_TOKEN}"}
12
-
13
-
14
- def generate_exegesis(passage):
15
- if not passage.strip():
16
- return "Please enter a Bible passage."
17
-
18
- prompt = f"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 with meanings. Historical and cultural context. Theological significance. for:\n\n{passage}\n\nExegesis:"
19
-
20
- payload = {
21
- "inputs": prompt,
22
- "parameters": {
23
- "max_length": 250,
24
- "temperature": 0.7,
25
- "do_sample": True
26
- }
27
- }
28
-
29
- try:
30
- response = requests.post(API_URL, headers=HEADERS, json=payload)
31
- response.raise_for_status() # Raise an error for bad responses (4xx, 5xx)
32
- result = response.json()
33
-
34
- if isinstance(result, list) and len(result) > 0:
35
- return result[0].get("generated_text", "Error: No response from model.")
36
- else:
37
- return "Error: Unexpected response format."
38
- except requests.exceptions.RequestException as e:
39
- return f"API Error: {e}"
40
-
41
- # Gradio interface
42
- demo = gr.Interface(
43
- fn=generate_exegesis,
44
- inputs=gr.Textbox(label="Enter Bible Passage", placeholder="e.g., John 3:16"),
45
- outputs=gr.Textbox(label="Exegesis Commentary"),
46
- title="JR Study Bible",
47
- description="Enter a Bible passage to receive insightful exegesis commentary using the Hugging Face API."
48
- )
49
-
50
- if __name__ == "__main__":
51
- demo.launch()
 
 
1
+ import os
2
+ import gradio as gr
3
+ import requests
4
+
5
+ # Retrieve the API token from environment variables
6
+ api_token = os.getenv("API_TOKEN")
7
+ if not api_token:
8
+ raise ValueError("API token not found. Please set the API_TOKEN environment variable.")
9
+
10
+ # Hugging Face Inference API Details
11
+ API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-3.2-1B-Instruct"
12
+ HEADERS = {"Authorization": f"Bearer {api_token}"}
13
+
14
+
15
+ def generate_exegesis(passage):
16
+ if not passage.strip():
17
+ return "Please enter a Bible passage."
18
+
19
+ prompt = f"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 with meanings. Historical and cultural context. Theological significance. for:\n\n{passage}\n\nExegesis:"
20
+
21
+ payload = {
22
+ "inputs": prompt,
23
+ "parameters": {
24
+ "max_length": 250,
25
+ "temperature": 0.7,
26
+ "do_sample": True
27
+ }
28
+ }
29
+
30
+ try:
31
+ response = requests.post(API_URL, headers=HEADERS, json=payload)
32
+ response.raise_for_status() # Raise an error for bad responses (4xx, 5xx)
33
+ result = response.json()
34
+
35
+ if isinstance(result, list) and len(result) > 0:
36
+ return result[0].get("generated_text", "Error: No response from model.")
37
+ else:
38
+ return "Error: Unexpected response format."
39
+ except requests.exceptions.RequestException as e:
40
+ return f"API Error: {e}"
41
+
42
+ # Gradio interface
43
+ demo = gr.Interface(
44
+ fn=generate_exegesis,
45
+ inputs=gr.Textbox(label="Enter Bible Passage", placeholder="e.g., John 3:16"),
46
+ outputs=gr.Textbox(label="Exegesis Commentary"),
47
+ title="JR Study Bible",
48
+ description="Enter a Bible passage to receive insightful exegesis commentary using the Hugging Face API."
49
+ )
50
+
51
+ if __name__ == "__main__":
52
+ demo.launch()