Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
import json
|
4 |
import os
|
5 |
|
6 |
-
# Configure the endpoint
|
7 |
ENDPOINT_URL = os.environ.get("ENDPOINT_URL", "https://z3xyxntalfy45pxc.us-east-1.aws.endpoints.huggingface.cloud")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Define the function to call your endpoint
|
10 |
def check_safety(input_text):
|
@@ -16,9 +22,10 @@ def check_safety(input_text):
|
|
16 |
"inputs": input_text
|
17 |
}
|
18 |
|
19 |
-
# Set headers
|
20 |
headers = {
|
21 |
-
"Content-Type": "application/json"
|
|
|
22 |
}
|
23 |
|
24 |
try:
|
@@ -51,6 +58,9 @@ with gr.Blocks(title="Safety Content Classifier", css="footer {display: none !im
|
|
51 |
gr.Markdown(f"# Safety Content Classifier")
|
52 |
gr.Markdown(f"## Connected to external safety model endpoint")
|
53 |
|
|
|
|
|
|
|
54 |
with gr.Accordion("About this demo", open=False):
|
55 |
gr.Markdown("""
|
56 |
This demo uses an external API endpoint to classify text based on safety policies.
|
@@ -95,4 +105,4 @@ with gr.Blocks(title="Safety Content Classifier", css="footer {display: none !im
|
|
95 |
)
|
96 |
|
97 |
# Launch the app
|
98 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
import os
|
4 |
|
5 |
+
# Configure the endpoint and authentication
|
6 |
ENDPOINT_URL = os.environ.get("ENDPOINT_URL", "https://z3xyxntalfy45pxc.us-east-1.aws.endpoints.huggingface.cloud")
|
7 |
+
HF_API_TOKEN = os.environ.get("HF_API_TOKEN") # Get API token from environment variable
|
8 |
+
|
9 |
+
# Check if the API token is configured
|
10 |
+
def is_token_configured():
|
11 |
+
if not HF_API_TOKEN:
|
12 |
+
return "⚠️ Warning: HF_API_TOKEN is not configured. The app won't work until you add this secret in your Space settings."
|
13 |
+
return "✅ API token is configured"
|
14 |
|
15 |
# Define the function to call your endpoint
|
16 |
def check_safety(input_text):
|
|
|
22 |
"inputs": input_text
|
23 |
}
|
24 |
|
25 |
+
# Set headers with authentication token
|
26 |
headers = {
|
27 |
+
"Content-Type": "application/json",
|
28 |
+
"Authorization": f"Bearer {HF_API_TOKEN}"
|
29 |
}
|
30 |
|
31 |
try:
|
|
|
58 |
gr.Markdown(f"# Safety Content Classifier")
|
59 |
gr.Markdown(f"## Connected to external safety model endpoint")
|
60 |
|
61 |
+
# Add token status indicator
|
62 |
+
token_status = gr.Markdown(is_token_configured())
|
63 |
+
|
64 |
with gr.Accordion("About this demo", open=False):
|
65 |
gr.Markdown("""
|
66 |
This demo uses an external API endpoint to classify text based on safety policies.
|
|
|
105 |
)
|
106 |
|
107 |
# Launch the app
|
108 |
+
demo.launch()
|