Spaces:
Runtime error
Runtime error
from fastapi import FastAPI | |
import requests | |
import os | |
app = FastAPI() | |
# Get token from environment variables (set in Hugging Face Secrets) | |
HF_TOKEN = os.getenv("HUGGING_FACE_HUB_TOKEN") | |
API_URL = "http://localhost:8080/generate" | |
async def generate_text(prompt: str, max_tokens: int = 200, temperature: float = 0.7): | |
payload = { | |
"inputs": prompt, | |
"parameters": { | |
"max_new_tokens": max_tokens, | |
"temperature": temperature, | |
"return_full_text": False | |
} | |
} | |
headers = {"Authorization": f"Bearer {HF_TOKEN}"} | |
response = requests.post(API_URL, json=payload, headers=headers) | |
return response.json() | |