Spaces:
Runtime error
Runtime error
| from fastapi import FastAPI, Form | |
| import requests | |
| import os | |
| from requests.exceptions import RequestException | |
| app = FastAPI() | |
| API_URL = "https://api-inference.huggingface.co/models/Noor22Tak/autotrain-6k0fa-2222" | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| headers = { | |
| "Authorization": f"Bearer {HF_TOKEN}" | |
| } | |
| def predict(description: str = Form(...)): | |
| try: | |
| payload = {"inputs": description} | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| response.raise_for_status() | |
| result = response.json() | |
| return {"result": result} | |
| except RequestException as e: | |
| return {"error": f"Request failed: {e}"} | |
| except ValueError: | |
| return {"error": "Failed to decode the response JSON"} | |
| except Exception as e: | |
| return {"error": f"An unexpected error occurred: {e}"} | |
| def welcome(): | |
| return {"message" : 'The Space is Running'} | |