Giter VIP home page Giter VIP logo

rahb-realtors-association / chat2gpt Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 1.0 297 KB

Chat²GPT is a ChatGPT (and DALL·E 2/3, and ElevenLabs) chat bot for Google Chat. 🤖💬

Home Page: https://chat2gpt.oncornerstone.app

License: MIT License

Python 73.27% HTML 21.06% JavaScript 3.85% Dockerfile 1.75% Procfile 0.06%
ai google-chat google-chat-bot google-cloud openai python dall-e elevenlabs text-to-speech docker bootstrap flask

chat2gpt's Introduction

Python 3.11 GCP Deployment Docker Image License: MIT

Logo


Chat²GPT is a ChatGPT chat bot for Google Chat 🤖💬. It's designed to amplify the experience in your Google Chat rooms by offering personalized user sessions for coherent dialogues, a manual reset capability, the power to generate images via OpenAI's DALL·E 2 API, and dynamic interactions through mentions or direct messaging. Moreover, with the integration of ElevenLabs' Text-to-Speech API, Chat²GPT now brings voice interactions, letting users convert textual prompts into audio. User input and text output is moderated with OpenAI's Moderation API.

📖 Table of Contents

🛠️ Setup

Run on Google Cloud

This bot is intended to be deployed on Google Cloud Functions, with audio data temporarily stored in Google Cloud Storage. Its continuous deployment pipeline is managed using GitHub Actions.

Follow these steps to setup your Chat²GPT bot:

1. Clone the Repository 📁

Clone this repository to your local machine using the command:

git clone https://github.com/RAHB-REALTORS-Association/chat2gpt.git

2. Create Google Cloud Project ☁️

Create a new project in your Google Cloud Console or select an existing one.

3. Create a Service Account and JSON Key 📑

In the Google Cloud Console:

  • Head to "IAM & Admin" > "Service Accounts".
  • Click "Create Service Account".
  • Assign a name and description, then hit "Create and Continue".
  • Grant this account the "Cloud Functions Developer" role for Cloud Functions creation and updating. If leveraging other Google Cloud services, additional roles may be required.
  • Click "Continue" and then "Done".
  • From the list, select the new service account.
  • Under the "Keys" tab, choose "Add Key" > "Create new key".
  • Opt for "JSON" as the key type and hit "Create". This auto-downloads the JSON key file to your device. This file, containing the service account credentials, facilitates GitHub Actions in deploying your function. Handle with caution.

When assigning roles to your service account:

  • For the bot to read/write objects and metadata in the Cloud Storage bucket, grant the "Storage Object Admin" (roles/storage.objectAdmin) role.
  • For the GitHub action to create and delete the bucket, grant the "Storage Admin" (roles/storage.admin) role.

4. Set GitHub Secrets 🔒

In your GitHub repository:

  • Navigate to "Settings" > "Secrets" > "New repository secret".
  • Add the following secrets:
    • GCP_PROJECT_ID: Your Google Cloud Project identifier.
    • GCP_FUNCTION: Your desired Google Cloud Function name.
    • GCP_REGION: Your chosen Google Cloud region.
    • GCP_SA_KEY: The entire JSON key file content that was downloaded in the previous step, encoded as base64.
    • OPENAI_API_KEY: Your OpenAI API key.
    • MODEL_NAME: The name of the OpenAI model you're using. Default: "gpt-3.5-turbo".
    • SYSTEM_PROMPT: The system prompt to use for the text-generation API.
    • PROMPT_PREFIX: Prefix added to beginning of user prompt for local model API. Default: LLaMa2 style.
    • PROMPT_SUFFIX: Suffix added to ending of user prompt for local model API. Default: LLaMa2 style.
    • MAX_TURNS: This sets the maximum number of exchanges the bot remembers in a user session before resetting. Default: 10 exchanges.
    • TTL: This sets the duration (in seconds) a user session stays active from the last received message before it resets. Default: 600 seconds (10 minutes).
    • MAX_TOKENS_INPUT: This sets the maximum number of tokens that can be sent. Default: 1000 tokens.
    • MAX_TOKENS_OUTPUT: This sets the maximum number of tokens that can be received. Default: 1000 tokens.
    • TEMPERATURE: This sets the temperature for the OpenAI API. Default: 0.8.
    • IMAGE_SIZE: This sets the image size for the DALL-E API. Default: "1024x1024".
    • IMAGE_STYLE: This sets the image style for the DALL-E API. Must choose between "natural", or "vivid". Default: "natural".
    • IMAGE_QUALITY: This sets the image quality for the DALL-E API, can be "standard" or "hd". Default: "standard".
    • DALLE_MODEL: This sets the DALL-E model for the DALL-E API. Must choose between "dall-e-2" or "dall-e-3". Default: "dall-e-2".
    • API_URL: This sets the API endpoint for the chat completions API. Default: "https://api.openai.com/v1/chat/completions".
    • ELEVENLABS_API_KEY: Your ElevenLabs API key. Can be disabled by omitting this secret.
    • ELEVENLABS_MODEL_NAME: ElevenLabs model you're using. Default: "eleven_multilingual_v2".
    • GCS_BUCKET_NAME: Your chosen name for the GCS bucket meant for TTS audio file storage.
    • MODERATION: Set to "False" to disable OpenAI's Moderation API. Default: "True".

5. GitHub Actions 🚀

The bot's deployment to Google Cloud Functions and Storage gets automatically handled by the GitHub Actions workflow upon pushing changes to the main branch.

6. Configure Bot Access 🤝

Now, your bot can be added to any room within your Google Workspace.

👷 Development

The server.py script included in this repository serves as a lightweight, local development server for Chat²GPT. This enables you to test new features, debug issues, or get a firsthand experience of the chatbot's capabilities without deploying it to a production environment. Running the server starts a web service that you can access at http://127.0.0.1:5000.

Setup

The following are only applicable if using the server.py script or Docker:

  • Additional environment variables:
    • LOG_FILE: Path to save server log file to. Default: None (disabled)
    • LOG_LEVEL: Enable Flask server debugging mode by setting to DEBUG. Default: INFO
    • HOST: Interfaces to bind server to. Default: 0.0.0.0
    • PORT: Port to bind server to. Default 5000

Docker 🐳

To quickly set up and run the Chat²GPT application, you can use the pre-built Docker image available at ghcr.io/rahb-realtors-association/chat2gpt:latest. Below are the steps and options for running the Docker container:

  1. Basic Usage

    Run the following command to pull the image and start a container:

    docker run -d -e OPENAI_API_KEY=sk-myopenaisecretapikey -p 5000:5000 --name chat2gpt ghcr.io/rahb-realtors-association/chat2gpt:latest
  2. Additional Options

    To load from .env file or persist logs, use volume mapping:

    docker run -d -v ./.env:/app/.env -v ./chat2gpt-server-log.txt:/app/chat2gpt-server-log.txt -e LOG_FILE=chat2gpt-server-log.txt -p 5000:5000 ghcr.io/rahb-realtors-association/chat2gpt:latest

    To access an API_URL running on the Docker host, use host networking:

    docker run -d -e API_URL=http://127.0.0.1:1234/v1/chat/completions --network host --name chat2gpt ghcr.io/rahb-realtors-association/chat2gpt:latest

The server should start successfully and can be accessed at http://127.0.0.1:5000.

Ubuntu 🤓

To run Chat²GPT on Ubuntu, follow these steps:

  1. Update Packages

    Open Terminal and update your package list:

    sudo apt update
  2. Install Required Dependencies

    Install Python and other necessary packages:

    sudo apt install python3 python3-pip git
  3. Clone the Repository

    Clone the Chat²GPT repository:

    git clone https://github.com/RAHB-REALTORS-Association/chat2gpt.git

    Navigate to the cloned directory:

    cd chat2gpt
  4. Install Python Packages

    Install the required Python packages:

    pip3 install -r requirements.txt
  5. Run the Server

    Start the Chat²GPT server:

    python3 server.py

The server should start successfully and can be accessed at http://127.0.0.1:5000.

macOS 🍎

To run Chat²GPT on macOS, you can use Homebrew to manage your packages. Follow these steps:

  1. Install Homebrew

    If you don't have Homebrew installed, open Terminal and run:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Python

    Install Python using Homebrew:

    brew install python
  3. Clone the Repository

    Clone the Chat²GPT repository:

    git clone https://github.com/RAHB-REALTORS-Association/chat2gpt.git

    Navigate to the cloned directory:

    cd chat2gpt
  4. Install Python Packages

    Install the required Python packages:

    pip3 install -r requirements.txt
  5. Run the Server

    Start the Chat²GPT server:

    python3 server.py

The server should start successfully and can be accessed at http://127.0.0.1:5000.

Android 🤖

To run Chat²GPT on an Android device using Termux, follow these steps:

  1. Update and Upgrade Termux Packages

    Open Termux and run the following command to update and upgrade existing packages:

    pkg upgrade
  2. Install Required Dependencies

    Install the necessary packages like OpenSSL, Python, pip, Git, Rust, and Binutils by executing:

    pkg install openssl python python-pip git rust binutils
  3. Clone the Repository

    Use the git command to clone the Chat²GPT repository to your device:

    git clone https://github.com/RAHB-REALTORS-Association/chat2gpt.git

    Navigate to the cloned directory:

    cd chat2gpt
  4. Install Python Packages

    Run the following command to install the Python packages required for Chat²GPT:

    pip install -r requirements.txt
  5. Run the Server

    Finally, start the Chat²GPT server using the python command:

    python server.py

The server should start successfully and can be accessed at http://127.0.0.1:5000.

🧑‍💻 Usage

  • Dynamic Interactions: Chat²GPT is attentive to its surroundings. You can invoke it in chat rooms by directly mentioning it using @botname. Alternatively, for more private interactions or queries, you can send a direct message to the bot.

  • Interactive Sessions: This bot remembers multiple rounds of a conversation per user, creating an illusion of continuous dialogue. It can even reference past questions or answers, mimicking a natural conversation flow.

  • Session Management: To maintain efficient performance, each conversation is limited by a configurable setting, recommended at 5-10 turns. Moreover, the bot keeps an eye on the time since the last message, auto-resetting the session if a set time limit is surpassed. And if needed, users can manually reset their own session anytime with the /reset command.

  • Image Generation: Want to visualize an idea? Use the /image <prompt> command. Based on the given prompt, which can range from a word to a paragraph, the bot leverages OpenAI's DALL·E 2 API to generate a relevant image.

  • Text-to-Speech (TTS): Utilize the power of Eleven Labs TTS API with the /tts <voice> <prompt> command. This command will return a voice response based on the given prompt in the specified voice. To see a list of available voices, use the /voices command.

  • Optimized Performance: We prioritize a smooth experience. Before processing any message, the bot checks its size by counting its tokens. If found too lengthy, an error message suggests the user to condense their message. This ensures uninterrupted bot interactions without straining the system.

  • Help On-Demand: Have questions on how to use Chat²GPT? Just type in the /help command. The bot fetches content directly from the docs/usage.md file, ensuring users get accurate, up-to-date information.

Remember, Chat²GPT is flexible, suitable for deployment on Google Cloud, FaaS (Function as a Service), or PaaS (Platform as a Service) environments, ensuring it's a perfect fit for all your Google Chat endeavors.

Commands ⌨️

Use the following commands for Chat²GPT:

  • /reset: Reinitialize your session.
  • /image <prompt>: Generate an image using OpenAI's DALL·E 2 API.
  • /tts <voice> <prompt>: Get a voice response with ElevenLabs' TTS API.
  • /voices: View available voices for TTS.
  • /help: Access accurate, up-to-date information from the docs.

🛡️ Privacy

Data Practices 📝

  • Ephemeral Conversations: Chat²GPT doesn't store or retain conversation history. Every session is temporary, ending when a conversation concludes or times out.

  • Temporary Audio Storage: Audio files are stored temporarily in Google Cloud Storage to allow users enough time for downloading. To ensure data privacy and efficient storage utilization, these files are deleted with each app redeployment.

  • Reactive Responses: The bot only reacts to direct prompts, such as @mentions or direct messages, and doesn't "read the room".

  • Anonymous Sessions: Users are tracked using anonymous ID numbers solely for session consistency. These IDs are cleared with each app redeployment.

AI APIs and User Awareness ℹ️

  • OpenAI's Commitment: We use OpenAI's APIs, which, as per OpenAI's policy, don't use user inputs for model training. More details are on OpenAI's official site.

  • ElevenLabs' Commitment: We use ElevenLabs' APIs, which, as per ElevenLabs' policy, don't use user inputs for model training. More details are on ElevenLabs' official site).

  • User Awareness: Discussing sensitive topics? Exercise caution, especially in group settings. Chat²GPT doesn't log conversations, but your organization or platform might.

🌐 Community

Contributing 👥

Contributions of any kind are very welcome, and would be much appreciated. 🙏 For Code of Conduct, see Contributor Covenant.

To get started, fork the repo, make your changes, add, commit and push the code, then come back here to open a pull request. If you're new to GitHub or open source, this guide or the git docs may help you get started, but feel free to reach out if you need any support.

Submit a PR

Reporting Bugs 🐛

If you've found something that doesn't work as it should, or would like to suggest a new feature, then go ahead and raise an issue on GitHub. For bugs, please outline the steps needed to reproduce, and include relevant info like system info and resulting logs.

Raise an Issue

📄 License

This project is open sourced under the MIT license. See the LICENSE file for more info.

chat2gpt's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar jhayesdev avatar justinh-rahb avatar sweep-ai[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

pittgo

chat2gpt's Issues

[Feature Request] Efficient GCS Bucket Deletion

🚀 Feature Request: Efficient GCS Bucket Deletion

Description:
Enhance the efficiency of file deletions in our GitHub Action, specifically in cases where there are a significant number of files.

Problem Statement:
Currently, our GitHub Action deletes files one by one, which can be time-consuming when there are many files to delete. The goal is to ensure rapid deletions without compromising the integrity of the operation, especially when the file count varies between deployments.

Proposed Solution:
Integrate the -m flag into the gsutil rm command in our GitHub Action. This will allow for multi-threaded operations and speed up the deletion of multiple files.

# Check if the bucket exists and delete it
- name: Delete Existing Bucket
  run: |
    if gsutil ls "gs://$GCS_BUCKET_NAME"; then
      gsutil -m rm -r "gs://$GCS_BUCKET_NAME"
    fi

Benefits:

  • Efficiency: Speeds up the deletion process for multiple files, reducing the overall runtime of the GitHub Action.
  • Scalability: Even if the number of files increases in the future, the operation will remain efficient.
  • Flexibility: The -m flag is adaptive, meaning it won't have a negative impact if there are fewer files or even none.

Additional Context:
In the current setup, when there are multiple files, the Action suggests using the -m flag for efficiency, as evident from the logs.

[Feature Request] Add /help command to print docs/usage.md

🚀 Feature Request

Description:
Add a new /help command to the chatbot that provides users with guidance on how to interact with it. This command will display content from the docs/usage.md file, allowing users to understand the bot's functionalities without having to refer to external documentation.

Problem Statement:
Users often require guidance on how to use chatbots effectively, especially when they encounter the bot for the first time. Providing them with a /help command directly within the chat interface can improve their experience by offering immediate access to helpful information.

Proposed Solution:
Implement a new /help command in the bot's message handling logic. Upon invocation, the bot should read the docs/usage.md file, extract the content below the --- header, and return it as its response. Here's a code snippet illustrating the proposed implementation:

# Check if the user input starts with /help
elif user_message.strip().lower() == '/help':
    try:
        # Read the docs/usage.md file
        with open('docs/usage.md', 'r') as file:
            content = file.read()

        # Split the content at the "---" header line and get the second part
        help_content = content.split("---", 2)[-1].strip()

        # Return the extracted content as the bot's response
        return jsonify({'text': help_content})

    except Exception as e:
        print(f"Error reading help content: {str(e)}")
        return jsonify({'text': 'Sorry, I encountered an error retrieving the help content.'})

Benefits:

  • Enhances user experience by providing immediate access to helpful guidance.
  • Reduces the need for users to search for external documentation.
  • Utilizes existing documentation, ensuring that the bot's guidance is consistent with other resources.

Additional Context:
The proposed solution assumes that the docs/usage.md file exists and is structured with a --- header. If the file structure changes in the future, the implementation may require adjustments.

Screenshots / Mockups (Optional):
N/A

[Refactor] Modularize main.py

Refactor

Description:
Refactor the existing main.py to adopt a more modular structure by dividing its functionalities into separate modules under different directories. This ensures clearer code organization and ease of maintainability.

Problem Statement:
The current structure of main.py is dense and combines multiple functionalities. This dense structure can hinder navigation, make debugging challenging, and complicate future extensions. Combining numerous responsibilities in one file can lead to decreased developer productivity and a heightened potential for errors.

Proposed Solution:

  1. Retain a stub for process_events() in main.py but move its core logic into the following directory and file structure:
    chat2gpt/
    │
    ├── main.py (contains a stub for process_event())
    │
    ├── handlers/
    │   ├── process_event.py (contains the actual logic for process_event())
    │   ├── chat_response.py
    │   ├── image_response.py
    │   ├── tts_response.py
    │   └── slash_commands.py
    │
    ├── settings/
    │   ├── env_loader.py
    │   └── sessions.py
    │
    └── utils/
        ├── moderation.py
        ├── voices.py
        ├── tokenizer.py
        ├── text_to_speech.py
        ├── google_cloud.py
        └── ...
    
  2. Segregate functionalities and transfer them into their respective files:
    • Move event processing logic to handlers/process_event.py.
    • Shift message handling to handlers/chat_response.py.
    • Transfer image response code to handlers/image_response.py.
    • Relocate TTS and voice list response functionality to handlers/tts_response.py.
    • Move any Google Cloud related functions to utils/google_cloud.py.
    • Move any voices related utility functions to utils/voices.py.
    • Move the text-to-speech function to utils/text_to_speech.py.
    • Move any slash command handling logic to handlers/slash_commands.py.
    • Transfer environment variable and session management to the settings/ directory, adopting a streamlined method using a loop or function to load environment variables.
    • Migrate any other auxiliary utility functions to the utils/ directory, including creating a function to centralize API call headers for the ElevenLabs API.
  3. Ensure all module imports remain absolute to prevent potential path issues and maintain clarity.
  4. Ensure that existing user input and output moderation rules are applied.

Benefits:

  • Enhanced code readability and maintainability.
  • Simplified project structure navigation.
  • Clearer separation of concerns, ensuring each module has a distinct responsibility.
  • Easier collaboration for developers, allowing them to work on separate modules with reduced risk of merge conflicts.

Additional Context:
This architectural change is pivotal for the sustainable evolution of the project. As we incorporate more features, having a well-defined and modular structure will be indispensable. Furthermore, breaking down functions like handle_message into more specific sub-functions will aid in readability and error management.

[Feature Request] Generate voices.json upon first run

🚀 Feature Request

Description:
Introduce an automated function to fetch and filter voice data, saving the results to data/voices_data.json.

Problem Statement:
Currently, the process of extracting and filtering voice data is manual. Automating this process will streamline data collection and ensure consistency in the data used across the project.

Proposed Solution:
Implement a function that:

  1. Downloads all the voice data.
  2. Filters the data to retain only voice_id, name, and labels for each voice entry.
  3. Saves the filtered data to data/voices_data.json.

The filtering process can be based on the given code snippet:

# Extract the list of voices and then filter it
voices_data = data["voices"]

filtered_voices = [
    {
        "voice_id": voice["voice_id"],
        "name": voice["name"],
        "labels": voice["labels"]
    }
    for voice in voices_data
]

Benefits:

  1. Simplifies the data extraction and filtering process.
  2. Ensures that the voice data used in the project is consistent and up-to-date.
  3. Reduces potential manual errors in the data preparation process.

Additional Context:
To automate the data extraction process, the function should interact with the ElevenLabs voices API. Here are the specifics of the API endpoint:

  • Endpoint: /v1/voices

  • Required Parameters: xi-api-key

  • Expected Response (200 Successful Response):

    • voices: A list containing voice data. Each voice entry has several fields, including voice_id, name, samples, category, fine_tuning, labels, etc.
    • For the purpose of our feature, we are primarily interested in voice_id, name, and labels.

    Sample response structure:

    {
      "voices": [
        {
          "voice_id": "string",
          "name": "string",
          ...
          "labels": {
            "additionalProp1": "string",
            "additionalProp2": "string",
            "additionalProp3": "string"
          },
          ...
        }
      ]
    }

The need for this feature was realized during a manual extraction process. Having an automated solution will be crucial as the project scales and voice data updates become more frequent.

[Feature Request] Dynamic style and quality for DALL-E 3 via prompt

🚀 Feature Request

Description:
Introduce a feature in our application that allows users to dynamically set the 'style' and 'quality' parameters for DALL-E 3 image generation at runtime through their prompts. This would be an enhancement over the current implementation, which uses global, static environment variables to set these parameters.

Problem Statement:
While our application currently supports setting DALL-E 3's 'style' and 'quality' parameters via environment variables, these settings are global and inflexible, applying uniformly to all images generated during a session. This setup limits the user's ability to tailor the style and quality of each image to their specific needs or preferences at the moment.

Proposed Solution:
Implement functionality where the application interprets specific hashtags within the user's text prompt (e.g., #natural, #vivid for style, and #standard, #hd for quality) and adjusts the 'style' and 'quality' parameters for that particular DALL-E 3 API call accordingly. The system should revert to the default values set by the environment variables if no relevant hashtags are detected in the prompt.

Benefits:
This feature would significantly enhance user experience by providing the flexibility to customize each image generation request. It would encourage creative experimentation with different styles and qualities, potentially leading to more engaging and diverse outputs. Furthermore, it adds an interactive element to the application, making it more responsive to user inputs.

Additional Context:
Given that users might not be familiar with the usage of these hashtags initially, it would be important to incorporate a user guide or help section explaining how to use these hashtags effectively. The feature should be designed to elegantly handle scenarios where users might input conflicting hashtags or invalid combinations.

[Bug] Images lack direct download functionality

🐛 Bug Report

Description:
Image cards within Chat²GPT are not directly clickable for downloading. While users can right-click to save the image, this doesn't provide an intuitive user experience.

Steps to Reproduce:

  1. Engage in a conversation using Chat²GPT where an image card response is triggered.
  2. Attempt to click directly on the image card to download or view the image in a separate tab.

Expected Behavior:
Users should be able to either click directly on the image to initiate a download or have a dedicated download button accompanying the image for easier access.

Actual Behavior:
Clicking directly on the image does nothing. Users are required to right-click and select 'Save Image As' to download.

Additional Information:
This issue might affect users who aren't familiar with the right-click method or expect a more direct approach to downloading images.

Possible Solution (Optional):
Consider implementing a direct click-to-download functionality for the image cards or adding a prominent 'Download' button adjacent to the images for better accessibility.

[Feature Request] Loading indicator for /image and /tts

🚀 Feature Request

Description:
Introduce an immediate feedback mechanism in the chatbot to notify users when their request is being processed, specifically for image and TTS generation. This will provide a more interactive and user-friendly experience.

Problem Statement:
Currently, there can be a noticeable delay between when the user sends a request (e.g., /image or /tts) and when the bot responds with the generated image or audio. During this waiting period, users are left without feedback, which might lead them to believe the bot is unresponsive or broken.

Proposed Solution:
Before starting the image or audio generation process, the bot should instantly send a response to inform the user that their request is being processed. This can be achieved by sending a "Processing..." message accompanied by a card that provides more details about the ongoing task. This will keep users informed and set the expectation that a more substantial response will follow shortly.

Benefits:

  • Enhances user experience by providing immediate feedback.
  • Reduces perceived waiting time.
  • Minimizes user uncertainty during processing-intensive tasks.

Additional Context:
Below is a code snippet that demonstrates a possible implementation:

# ... existing code ...

def handle_message(user_id, user_message):
    try:
        # ... existing code ...

        # Check if the user input starts with /image
        elif user_message.strip().lower().startswith('/image'):
            # ... existing code ...
            
            # Before the actual image generation, immediately respond with a processing message
            return jsonify({
                'text': 'Processing your image request...',
                'cardsV2': [{
                    'cardId': generate_unique_card_id(),
                    'card': {
                        'header': {
                            'title': 'Processing...',
                        },
                        'sections': [
                            {
                                'widgets': [
                                    {
                                        'textParagraph': {
                                            'text': 'Generating the image based on your request. Please wait...'
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }],
            })

        # Check if the user input starts with /tts
        elif user_message.strip().lower().startswith('/tts'):
            # ... existing code ...
            
            # Before the actual text-to-speech conversion, immediately respond with a processing message
            return jsonify({
                'text': 'Processing your TTS request...',
                'cardsV2': [{
                    'cardId': generate_unique_card_id(),
                    'card': {
                        'header': {
                            'title': 'Processing...',
                        },
                        'sections': [
                            {
                                'widgets': [
                                    {
                                        'textParagraph': {
                                            'text': 'Generating the speech output based on your request. Please wait...'
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }],
            })

        # ... rest of the code ...

    except Exception as e:
        # ... existing code ...

Screenshots / Mockups (Optional):
No visual mockups provided.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.