Spaces:
Runtime error
Runtime error
|
Download docs/huggingface.md from Safe-Harbor/LLMGuardian: direct link, hf CLI and curl.
- Browser
- Download file 2.87 kB
-
https://huggingface.co/spaces/Safe-Harbor/LLMGuardian/resolve/main/docs/huggingface.md
- Command line
-
hf download hf://spaces/Safe-Harbor/LLMGuardian/docs/huggingface.md
-
curl -L -o huggingface.md https://huggingface.co/spaces/Safe-Harbor/LLMGuardian/resolve/main/docs/huggingface.md
2.87 kB
A newer version of the Gradio SDK is available: 6.32.0
Running in Huggingface
To run the LLMGuardian application on Huggingface, follow these steps:
Setting Up the Environment
Fork the Repository:
- Fork the LLMGuardian repository to your own GitHub account.
Clone the Repository:
git clone https://github.com/your-username/LLMGuardian.git cd LLMGuardianCreate and Activate a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`Install Dependencies:
pip install -r requirements/base.txt
Setting Up the Backend (FastAPI)
Create FastAPI Backend:
- Implement model scanning endpoints.
- Add prompt injection detection.
- Include input/output validation.
- Implement rate limiting middleware.
- Add authentication checks.
Install FastAPI and Uvicorn:
pip install fastapi uvicornCreate
main.pyfor FastAPI:from fastapi import FastAPI, HTTPException app = FastAPI() @app.get("/") async def read_root(): return {"message": "Welcome to LLMGuardian"} # Add your endpoints here if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)Run the FastAPI Server:
uvicorn main:app --reload
Setting Up the Frontend (Gradio)
Create Gradio UI Frontend:
- Implement model security testing interface.
- Add vulnerability scanning dashboard.
- Include real-time attack detection.
- Add configuration settings.
Install Gradio:
pip install gradioCreate
app.pyfor Gradio:import gradio as gr def security_test_interface(prompt): # Implement your security test logic here return "Security test result" iface = gr.Interface(fn=security_test_interface, inputs="text", outputs="text") iface.launch()Run the Gradio Interface:
python app.py
Deploying to Huggingface Spaces
Create a New Space:
- Go to Huggingface Spaces and create a new Space.
- Choose Gradio as the SDK.
Push Your Code to the Space:
- Add your Huggingface Space as a remote repository:
git remote add space https://huggingface.co/spaces/your-username/LLMGuardian - Push your code to the Space:
git push space main
- Add your Huggingface Space as a remote repository:
Configure the Space:
- Ensure that the
app.pyfile is in the root directory of your repository. - Huggingface will automatically detect and run the
app.pyfile.
- Ensure that the
Conclusion
Your LLMGuardian application should now be running on Huggingface Spaces with a FastAPI backend and a Gradio frontend. You can access it via the URL provided by Huggingface Spaces.