Skip to content
Go back

FastAPI-based web application

Updated:
Edit page

This project is a FastAPI-based web application designed to automate key processes for businesses seeking support in Corporate Social Responsibility (CSR) and financial aid. It consists of two main components, each addressing a distinct need:

Table of contents

Open Table of contents

CSR Quote Generation Module

It processes client data to calculate a ‘maturity score’ and ‘ponderation ambition’, then recommends tailored service packages with pricing.

User Input Collection

A multi-step form built in Webflow collects structured company data—including company name, location, company size, environmental and social practices, and interest in financial aid— and sends it to the FastAPI backend via a POST webhook upon submission.

Maturity Score Calculation

The backend then processes this data to deliver two key functionalities: calculating CSR (Corporate Social Responsibility) maturity and ambition scores to generate personalized service offers.


  def calculate_offer_components(
      self,
       maturity_results: Dict[str, float],
      ambition_results: Dict[str, float]
  ) -> Dict[str, float]:
      """
      Calculate each offer component based on maturity, ambition, and internal priority weights.
      Returns:
          Dict[str, float]: offer values with keys like 'bilan_carbone_offer'
      """
      offre = {}
      ponderation = ambition_results.get('ponderation_ambition', 1.0)

      for key, maturity_score in maturity_results.items():
          priority_weight = self.priorities.get(key, 1.0)  # default to 1 if not in priorities
          offer_key = f"{key}_offer"
          offre[offer_key] = maturity_score * ponderation * priority_weight

      return offresrc/styles/global.css

Financial Aid Filtering & Analysis Module

This application integrates with OpenAI to analyze and recommend personalized financial aid using an AI agent. The agent intelligently searches and suggests the most relevant government aid programs based on key company attributes such as size, location, and NAF code.


class OpenAIProgramProcessor:
    """
    Processes programs using OpenAI's function calling to extract specific information.
    Processes all programs in a single API call for efficiency.
    """

    def __init__(self, api_key: Optional[str] = None):
        """
        Initialize the OpenAI program processor.

        Args:
            api_key: OpenAI API key. If not provided, will try to use OPENAI_API_KEY env variable.
        """
        self.api_key = api_key or os.environ.get("OPENAI_API_KEY")
        if not self.api_key:
            raise ValueError(
                "OpenAI API key must be provided or set as OPENAI_API_KEY environment variable"
            )
        self.client = OpenAI(api_key=self.api_key)

    def process_programs(self, programs: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
        """
        Process multiple programs to extract key information in a single API call.

        Args:
            programs: List of program dictionaries to process

        Returns:
            List of programs with extracted information added
        """
        if not programs:
            return []
            
        formatted_programs = self._format_programs_for_query(programs)
        
        # Define our function calling schema using Pydantic model
        tools = [
            {
                "type": "function",
                "function": {
                    "name": "extract_all_programs_details",
                    "description": "Extract key details from multiple financial aid programs",
                    "parameters": ProgramsExtraction.model_json_schema()
                }
            }
        ]

        # Call OpenAI API with function calling for batch processing
        response = self.client.chat.completions.create(
            model="gpt-4-turbo",  # Use appropriate model
            messages=[
                {"role": "system", "content": (
                    "You are a financial aid analyst that extracts key information from program descriptions. "
                    "Your task is to identify for each program: the name, cost, duration, and calculate the final price "
                    "for the user. For programs that provide financial help for specific work or projects, "
                    "calculate the final price after the help is applied. For formations and other non-deductible "
                    "helps, simply provide the price. Process all programs in a single response."
                )},
                {"role": "user", "content": f"Extract information from these financial aid programs:\n\n{formatted_programs}"}
            ],
            tools=tools,
            tool_choice={"type": "function", "function": {"name": "extract_all_programs_details"}}, 
        )

        print(response)

        # Extract function call results
        tool_call = response.choices[0].message.tool_calls[0]
        extracted_data = json.loads(tool_call.function.arguments)
'''


## Matching Logic

You can configure share links in `SHARE_LINKS` object inside `src/constants.ts`.

![An arrow pointing at share link icons](https://github.com/user-attachments/assets/4f930b68-b625-45df-8c41-e076dd2b838e)

## Conclusion

This is the brief specification of how you can customize this theme. You can customize more if you know some coding. For customizing styles, please read [this article](https://astro-paper.pages.dev/posts/customizing-astropaper-theme-color-schemes/). Thanks for reading.✌🏻src/styles/global.css

Edit page
Share this post on:

Previous Post
Geomagnetic Signal Analysis Based Classification of Earthquake Magnitudes
Next Post
Extract Spacial information from Scanned PDF file