Update app.py
Browse files
app.py
CHANGED
@@ -16,8 +16,8 @@ app = FastAPI()
|
|
16 |
logging.basicConfig(level=logging.INFO)
|
17 |
logger = logging.getLogger(__name__)
|
18 |
|
19 |
-
# Hugging Face Inference API endpoint for
|
20 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
21 |
headers = {"Authorization": f"Bearer {token}"}
|
22 |
|
23 |
# Define request body schema
|
@@ -49,7 +49,11 @@ async def generate_text(request: TextGenerationRequest):
|
|
49 |
|
50 |
# Send request to the Hugging Face Inference API
|
51 |
response = requests.post(API_URL, headers=headers, json=payload)
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
|
54 |
# Extract the generated text from the response
|
55 |
generated_text = response.json()[0]["generated_text"]
|
|
|
16 |
logging.basicConfig(level=logging.INFO)
|
17 |
logger = logging.getLogger(__name__)
|
18 |
|
19 |
+
# Hugging Face Inference API endpoint for DeepSeek
|
20 |
+
API_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B" # Replace with the correct model ID
|
21 |
headers = {"Authorization": f"Bearer {token}"}
|
22 |
|
23 |
# Define request body schema
|
|
|
49 |
|
50 |
# Send request to the Hugging Face Inference API
|
51 |
response = requests.post(API_URL, headers=headers, json=payload)
|
52 |
+
|
53 |
+
# Check for errors in the response
|
54 |
+
if response.status_code != 200:
|
55 |
+
logger.error(f"API Error: {response.status_code} - {response.text}")
|
56 |
+
raise HTTPException(status_code=response.status_code, detail=response.text)
|
57 |
|
58 |
# Extract the generated text from the response
|
59 |
generated_text = response.json()[0]["generated_text"]
|