roh8exe commited on
Commit
b3c518d
·
verified ·
1 Parent(s): 74706d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import requests
3
  import os
4
 
5
- # Hugging Face API Token (Set in Hugging Face Spaces)
6
  HF_API_TOKEN = os.getenv("HF_API_TOKEN")
7
 
8
  # Hugging Face model endpoints
@@ -17,10 +17,22 @@ def get_toxicity_prediction(text, language):
17
  return "Error: Model not found for the selected language"
18
 
19
  url = MODEL_ENDPOINTS[language]
20
- headers = {"Authorization": f"Bearer {HF_API_TOKEN}"}
21
-
22
- # Send request to Hugging Face API
23
- response = requests.post(url, headers=headers, json={"inputs": text, "parameters": {"return_all_scores": True}})
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  if response.status_code == 200:
26
  predictions = response.json()[0] # Extract first prediction result
 
2
  import requests
3
  import os
4
 
5
+ # Hugging Face API Token (Set this in Hugging Face Spaces)
6
  HF_API_TOKEN = os.getenv("HF_API_TOKEN")
7
 
8
  # Hugging Face model endpoints
 
17
  return "Error: Model not found for the selected language"
18
 
19
  url = MODEL_ENDPOINTS[language]
20
+ headers = {
21
+ "Authorization": f"Bearer {HF_API_TOKEN}",
22
+ "Content-Type": "application/json"
23
+ }
24
+
25
+ payload = {
26
+ "inputs": text,
27
+ "parameters": {
28
+ "return_all_scores": True
29
+ },
30
+ "options": {
31
+ "wait_for_model": True # Ensures the model loads if it's inactive
32
+ }
33
+ }
34
+
35
+ response = requests.post(url, headers=headers, json=payload)
36
 
37
  if response.status_code == 200:
38
  predictions = response.json()[0] # Extract first prediction result