Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,18 +5,21 @@ import os
|
|
5 |
# Load API URL and token from environment variables
|
6 |
API_URL = os.getenv("HF_API_URL", "https://api-inference.huggingface.co/models/your-model")
|
7 |
API_TOKEN = os.getenv("HF_API_TOKEN", "your-default-token") # Replace with your actual token for fallback
|
8 |
-
|
9 |
-
print(f"Token: {'*****' if API_TOKEN else 'Token not set'}")
|
10 |
# Function to call the Hugging Face Inference API
|
11 |
def call_huggingface_api(input_text):
|
12 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
13 |
payload = {"inputs": input_text}
|
14 |
try:
|
15 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
|
|
|
|
16 |
if response.status_code == 200:
|
17 |
data = response.json()
|
18 |
return f"Question: {input_text}\nAnswer: {data.get('answer', 'No answer found.')}\nConfidence: {data.get('confidence', 'N/A')}"
|
19 |
else:
|
|
|
20 |
return f"Error: {response.status_code} - {response.text}"
|
21 |
except Exception as e:
|
22 |
return f"Error during API call: {e}"
|
|
|
5 |
# Load API URL and token from environment variables
|
6 |
API_URL = os.getenv("HF_API_URL", "https://api-inference.huggingface.co/models/your-model")
|
7 |
API_TOKEN = os.getenv("HF_API_TOKEN", "your-default-token") # Replace with your actual token for fallback
|
8 |
+
|
|
|
9 |
# Function to call the Hugging Face Inference API
|
10 |
def call_huggingface_api(input_text):
|
11 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
12 |
payload = {"inputs": input_text}
|
13 |
try:
|
14 |
response = requests.post(API_URL, headers=headers, json=payload)
|
15 |
+
print(f"Request sent to: {API_URL}")
|
16 |
+
print(f"Payload: {payload}")
|
17 |
+
print(f"Response Status Code: {response.status_code}")
|
18 |
if response.status_code == 200:
|
19 |
data = response.json()
|
20 |
return f"Question: {input_text}\nAnswer: {data.get('answer', 'No answer found.')}\nConfidence: {data.get('confidence', 'N/A')}"
|
21 |
else:
|
22 |
+
print(f"Error Response: {response.text}")
|
23 |
return f"Error: {response.status_code} - {response.text}"
|
24 |
except Exception as e:
|
25 |
return f"Error during API call: {e}"
|