Spaces:
Runtime error
Runtime error
Download app.py from VSPLC/integration: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/VSPLC/integration/resolve/main/app.py
- Command line
-
hf download hf://spaces/VSPLC/integration/app.py
-
curl -L -o app.py https://huggingface.co/spaces/VSPLC/integration/resolve/main/app.py
1.27 kB
| from fastapi import FastAPI | |
| from llama_index_llms_huggingface_api import HuggingFaceInferenceAPI | |
| from pydantic import BaseModel | |
| # Define your Pydantic model with protected namespaces disabled | |
| class ModelConfig(BaseModel): | |
| model_id: str | |
| model_name: str | |
| class Config: | |
| protected_namespaces = () # Disable protected namespaces warning | |
| # Define Settings class | |
| class Settings: | |
| llm = None # Initialize the llm attribute | |
| # Initialize FastAPI app | |
| app = FastAPI() | |
| # Set up the HuggingFaceInferenceAPI with the new class | |
| Settings.llm = HuggingFaceInferenceAPI( | |
| api_key="your_api_key", # Replace with your actual API key | |
| model_name="your_model_name" # Replace with your actual model name | |
| ) | |
| # Sample endpoint to test the LLM | |
| async def predict(input_text: str): | |
| try: | |
| response = Settings.llm.generate(input_text) # Replace with the appropriate method for your API | |
| return {"prediction": response} | |
| except Exception as e: | |
| return {"error": str(e)} | |
| # Sample endpoint to retrieve model configuration | |
| async def get_model_config(): | |
| return {"model_id": Settings.llm.model_id, "model_name": Settings.llm.model_name} | |
| # Run the app using: uvicorn app:app --reload | |