Spaces:
Runtime error
Runtime error
Download app.py from adaptiveaiventures/llama2-interference: direct link, hf CLI and curl.
- Browser
- Download file 695 Bytes
-
https://huggingface.co/spaces/adaptiveaiventures/llama2-interference/resolve/main/app.py
- Command line
-
hf download hf://spaces/adaptiveaiventures/llama2-interference/app.py
-
curl -L -o app.py https://huggingface.co/spaces/adaptiveaiventures/llama2-interference/resolve/main/app.py
695 Bytes
| 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() | |