CoolFace
Apppublic

DebopamC/AI_Financial_Dispute_Automation

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
App README

AI-Powered Dispute Resolution

![Build Status](https://github.com/DebopamParam/AI-PoweredDisputeResolution/actions) ![Version](https://github.com/DebopamParam/AI-PoweredDisputeResolution/releases) ![License](https://github.com/DebopamParam/AI-PoweredDisputeResolution/blob/main/LICENSE) ![Python Version](https://www.python.org/) ![FastAPI](https://fastapi.tiangolo.com/) ![Streamlit](https://streamlit.io/) ![LangChain](https://langchain.com/) ![Gemini API](https://ai.google.dev/) ![Hugging Face Spaces](https://huggingface.co/spaces)

๐Ÿ“‹ Table of Contents

๐Ÿ” Overview

The AI-Powered Dispute Resolution system is designed to streamline the process of analyzing and resolving disputes using advanced AI technologies. This application leverages large language models to analyze dispute details, identify key issues, suggest potential solutions, and provide legal references. The system is primarily designed to operate as a standalone application on Hugging Face Spaces, combining a user-friendly Streamlit frontend with a robust FastAPI backend.

โœจ Key Features

AI-Powered Analysis

  • โ€”Intelligent Dispute Processing: Analyzes dispute details using Gemini API to extract key information
  • โ€”Solution Recommendation: Suggests potential resolutions based on similar historical cases
  • โ€”Legal Reference Integration: Provides relevant legal references and precedents
  • โ€”Continuous Learning: System improves over time by incorporating feedback from resolved cases

Frontend Capabilities

  • โ€”Intuitive Interface: User-friendly Streamlit interface for submitting and tracking disputes
  • โ€”Dashboard: Real-time visualization of dispute status and analytics
  • โ€”Document Upload: Support for uploading relevant documents in various formats
  • โ€”Explainable AI: Clear explanations of how the AI reached its conclusions

Backend Robustness

  • โ€”Secure API: FastAPI backend ensuring secure data processing
  • โ€”Efficient Data Management: Optimized database schema for quick retrieval and analysis
  • โ€”Scalable Architecture: Designed to handle increasing volumes of disputes
  • โ€”Comprehensive Logging: Detailed activity logs for auditing purposes

Deployment Strategy

  • โ€”Hugging Face Integration: Seamless deployment on Hugging Face Spaces
  • โ€”Single Container Solution: Entire application packaged in a single Docker container
  • โ€”Environment Variable Configuration: Easy configuration through environment variables

๐Ÿ—๏ธ Architecture Overview

High-Level System Diagram

mermaid
graph TD
    A[User] -->|Submits Dispute| B[Streamlit Frontend]
    B -->|API Request| C[FastAPI Backend]
    C -->|Query| D[Database]
    C -->|Analysis Request| E[Gemini API]
    E -->|Analysis Results| C
    C -->|Response| B
    B -->|Display Results| A
    style A fill:#f9f,stroke:#333,stroke-width:2px
    style B fill:#bbf,stroke:#333,stroke-width:2px
    style C fill:#bfb,stroke:#333,stroke-width:2px
    style D fill:#fbb,stroke:#333,stroke-width:2px
    style E fill:#bff,stroke:#333,stroke-width:2px

The diagram above illustrates the flow of data through the system, from user input to AI analysis and result presentation.

Component Interaction Diagram

mermaid
sequenceDiagram
    participant User
    participant Frontend as Streamlit Frontend
    participant Backend as FastAPI Backend
    participant DB as Database
    participant AI as Gemini API

    User->>Frontend: Submit dispute details
    Frontend->>Backend: POST /api/disputes
    Backend->>DB: Store dispute data
    Backend->>AI: Request analysis
    AI->>Backend: Return analysis results
    Backend->>DB: Update with analysis
    Backend->>Frontend: Return dispute ID & status
    Frontend->>User: Display confirmation
    User->>Frontend: View analysis results
    Frontend->>Backend: GET /api/disputes/{id}
    Backend->>DB: Retrieve dispute data
    DB->>Backend: Return dispute data
    Backend->>Frontend: Return complete dispute info
    Frontend->>User: Display analysis results

This sequence diagram shows the typical flow when a user submits a dispute for analysis.

Deployment Architecture Diagram

mermaid
graph TD
    A[Hugging Face Space] -->|Container| B[Docker Container]
    B -->|Port 8000| C[FastAPI Backend]
    B -->|Port 8501| D[Streamlit Frontend]
    C -->|Internal Communication| D
    C -->|Database| E[SQLite]
    style A fill:#f9f,stroke:#333,stroke-width:2px
    style B fill:#bbf,stroke:#333,stroke-width:2px
    style C fill:#bfb,stroke:#333,stroke-width:2px
    style D fill:#fbb,stroke:#333,stroke-width:2px
    style E fill:#bff,stroke:#333,stroke-width:2px

The deployment architecture shows how the application is packaged in a single Docker container for deployment on Hugging Face Spaces.

Database Schema Diagram

mermaid
erDiagram
    DISPUTES {
        string id PK
        string title
        string description
        datetime created_at
        string status
        string user_id FK
    }
    ANALYSIS {
        string id PK
        string dispute_id FK
        string key_issues
        string suggested_solutions
        string legal_references
        datetime created_at
    }
    USERS {
        string id PK
        string username
        string email
        datetime created_at
    }
    FEEDBACK {
        string id PK
        string analysis_id FK
        int rating
        string comments
        datetime created_at
    }
    DISPUTES ||--o{ ANALYSIS : has
    USERS ||--o{ DISPUTES : submits
    ANALYSIS ||--o{ FEEDBACK : receives

This ER diagram shows the database structure used to store dispute information, analysis results, user data, and feedback.

User Flow Diagram

mermaid
graph TD
    A[Start] --> B[Create Account/Login]
    B --> C[Submit New Dispute]
    C --> D[Upload Supporting Documents]
    D --> E[View Initial AI Analysis]
    E --> F{Satisfied with Analysis?}
    F -->|Yes| G[Accept Recommendations]
    F -->|No| H[Request Detailed Analysis]
    H --> I[Review Detailed Analysis]
    I --> J{Accept Solution?}
    J -->|Yes| K[Implement Solution]
    J -->|No| L[Provide Feedback]
    L --> M[Receive Refined Analysis]
    M --> J
    G --> N[Provide Feedback on Process]
    K --> N
    N --> O[End]
    style A fill:#f9f,stroke:#333,stroke-width:2px
    style F fill:#bbf,stroke:#333,stroke-width:2px
    style J fill:#bbf,stroke:#333,stroke-width:2px
    style O fill:#f9f,stroke:#333,stroke-width:2px

This diagram illustrates the typical user journey through the dispute resolution process.

๐Ÿ› ๏ธ Technologies Used

๐Ÿ“‹ Prerequisites

To run this application, you need:

  • โ€”Python 3.9 or higher
  • โ€”Docker and Docker Compose
  • โ€”Gemini API key
  • โ€”Hugging Face account (for deployment)

๐Ÿ”ง Installation

  1. 1.Clone the repository:
bash
   git clone https://github.com/DebopamParam/AI-Powered_Dispute_Resolution.git
   cd AI-Powered_Dispute_Resolution
  1. 1.Create a .env file in the root directory with the following variables:
   GEMINI_API_KEY=your_gemini_api_key
   DATABASE_URL=sqlite:///./app.db
   DEBUG=False
  1. 1.Build the Docker image:
bash
   docker build -t dispute-resolution-app .

โš™๏ธ Configuration

Environment Variables

The application can be configured using the following environment variables:

  • โ€”GEMINI_API_KEY - Your Gemini API key
  • โ€”DATABASE_URL - Database connection string (defaults to SQLite)
  • โ€”DEBUG - Enable debug mode (True/False)
  • โ€”LOG_LEVEL - Logging level (INFO, DEBUG, ERROR)
  • โ€”MAX_UPLOAD_SIZE - Maximum file upload size in MB

Optional Configuration Files

You can also create the following configuration files:

  • โ€”config/app_config.json - Application-specific settings
  • โ€”config/model_config.json - AI model parameters

๐Ÿ“ Usage

Running Locally

  1. 1.Start the application using Docker Compose:
bash
   docker-compose up
  1. 1.Navigate to http://localhost:8501 in your web browser

Quickstart Guide

  1. 1.Create an account or log in
  2. 2.Click on "Create New Dispute"
  3. 3.Fill in the dispute details:
  4. 4.Title
  5. 5.Description
  6. 6.Parties involved
  7. 7.Relevant dates
  8. 8.Upload any supporting documents
  9. 9.Click "Submit for Analysis"
  10. 10.Wait for the AI to analyze the dispute
  11. 11.Review the analysis results, which include:
  12. 12.Key issues identified
  13. 13.Suggested solutions
  14. 14.Legal references
  15. 15.Provide feedback on the analysis
  16. 16.Implement the recommended solutions

๐Ÿ“š API Documentation

The API documentation is automatically generated and available at /docs when running the application. It provides:

  • โ€”Complete list of endpoints
  • โ€”Request and response schemas
  • โ€”Authentication requirements
  • โ€”Example requests
  • โ€”Interactive testing capabilities

๐Ÿงช Testing

To run the tests:

bash
# Run all tests
python -m pytest

# Run specific test file
python -m pytest tests/test_api.py

# Run with coverage report
python -m pytest --cov=app tests/

๐Ÿš€ Deployment

Deploying to Hugging Face Spaces

  1. 1.Fork this repository
  2. 2.Create a new Space on Hugging Face:
  3. 3.Type: Docker
  4. 4.Repository: Your forked repository
  5. 5.Add the following secrets to your Space:
  6. 6.GEMINI_API_KEY - Your Gemini API key
  7. 7.The Space will automatically build and deploy the application

Deploying Locally with Docker Compose

  1. 1.Make sure Docker and Docker Compose are installed
  2. 2.Create the .env file as described in the Installation section
  3. 3.Run the following command:
bash
   docker-compose up -d
  1. 1.Access the application at http://localhost:8501

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. 1.Fork the repository
  2. 2.Create a new branch (git checkout -b feature/amazing-feature)
  3. 3.Make your changes
  4. 4.Commit your changes (git commit -m 'Add some amazing feature')
  5. 5.Push to the branch (git push origin feature/amazing-feature)
  6. 6.Open a Pull Request

Please make sure your code follows the project's coding standards and includes appropriate tests.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘ Acknowledgments

๐Ÿ“ž Contact/Support

  • โ€”For bug reports and feature requests, please open an issue

โš ๏ธ Disclaimer

This project is a prototype and should be used with caution. The AI-generated recommendations should not be considered legal advice. Always consult with a qualified legal professional for legal matters.