LLMGuardian / docs /huggingface.md
DeWitt Gibson
Create huggingface.md
04b95eb
|
Raw History Blame Contribute Delete
2.87 kB

A newer version of the Gradio SDK is available: 6.32.0

Upgrade

Running in Huggingface

To run the LLMGuardian application on Huggingface, follow these steps:

Setting Up the Environment

  1. Fork the Repository:

    • Fork the LLMGuardian repository to your own GitHub account.
  2. Clone the Repository:

    git clone https://github.com/your-username/LLMGuardian.git
    cd LLMGuardian
    
  3. Create and Activate a Virtual Environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
    
  4. Install Dependencies:

    pip install -r requirements/base.txt
    

Setting Up the Backend (FastAPI)

  1. Create FastAPI Backend:

    • Implement model scanning endpoints.
    • Add prompt injection detection.
    • Include input/output validation.
    • Implement rate limiting middleware.
    • Add authentication checks.
  2. Install FastAPI and Uvicorn:

    pip install fastapi uvicorn
    
  3. Create main.py for 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)
    
  4. Run the FastAPI Server:

    uvicorn main:app --reload
    

Setting Up the Frontend (Gradio)

  1. Create Gradio UI Frontend:

    • Implement model security testing interface.
    • Add vulnerability scanning dashboard.
    • Include real-time attack detection.
    • Add configuration settings.
  2. Install Gradio:

    pip install gradio
    
  3. Create app.py for 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()
    
  4. Run the Gradio Interface:

    python app.py
    

Deploying to Huggingface Spaces

  1. Create a New Space:

  2. 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
      
  3. Configure the Space:

    • Ensure that the app.py file is in the root directory of your repository.
    • Huggingface will automatically detect and run the app.py file.

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.