by 9davidmuia
Text to Context Converter
import logging
import os
from app_init import create_initialized_flask_app
from shared_resources import twilio_client
# Flask app creation should be done by create_initialized_flask_app to avoid circular dependency problems.
app = create_initialized_flask_app()
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
if __name__ == "__main__":
logger.info("Starting the application...")
app.run(host='0.0.0.0', port=8080, debug=True)
logger.info("Application stopped.")
logger.info("Application stopped.")
Created: | Last Updated:
Here's a step-by-step guide on how to use the Text to Context Converter template:
Introduction
The Text to Context Converter is a powerful tool that analyzes user-provided text and generates contextual insights using ChatGPT. This template creates a web application with both a user interface and a WhatsApp integration, allowing users to input text and receive detailed analysis results.
Getting Started
- Click "Start with this Template" to begin using the Text to Context Converter in your Lazy project.
Setting Up Environment Secrets
Before running the app, you need to set up the following environment secrets:
- Navigate to the Environment Secrets tab in the Lazy Builder.
- Add the following secrets:
TWILIO_ACCOUNT_SID
: Your Twilio Account SIDTWILIO_AUTH_TOKEN
: Your Twilio Auth TokenTWILIO_WHATSAPP_NUMBER
: Your Twilio WhatsApp number
To obtain these values:
- Sign up for a Twilio account at https://www.twilio.com/ if you haven't already.
- Log in to your Twilio Console.
- Find your Account SID and Auth Token on the dashboard.
- To get a WhatsApp number, navigate to "Messaging" > "Try it out" > "Send a WhatsApp message" and follow the instructions to set up a WhatsApp Sandbox.
Testing the App
- Click the "Test" button in the Lazy Builder interface to deploy and run the application.
- Wait for the deployment process to complete.
Using the Web Interface
Once the app is deployed, you'll receive a server link to access the web interface. Here's how to use it:
- Open the provided link in your web browser.
- You'll see a text area where you can enter the text you want to analyze.
- Type or paste your text into the text area.
- Click the "Analyze" button to submit your text for analysis.
- The results will appear below the form, including a summary, context, key points, and urgency level.
Using the WhatsApp Integration
To use the WhatsApp integration:
- Add the Twilio WhatsApp Sandbox number to your contacts.
- Send a message to this number with the text you want to analyze.
- The bot will respond with the analysis results, including summary, context, key points, and urgency level.
Integrating the App
If you want to integrate this app into your own service or frontend, you can use the provided API endpoint:
- Use the
/analyze
endpoint to submit text for analysis. - Send a POST request to
https://your-app-url/analyze
with the following JSON payload:
json
{
"text": "Your text to analyze goes here"
}
- The API will respond with a JSON object containing the analysis results:
json
{
"summary": "A brief summary of the text",
"context": "The context of the text",
"key_points": ["Key point 1", "Key point 2", "Key point 3"],
"urgency": "low|medium|high"
}
You can also programmatically send WhatsApp messages using the /send_whatsapp
endpoint:
- Send a POST request to
https://your-app-url/send_whatsapp
with the following JSON payload:
json
{
"to_number": "+1234567890",
"message": "Your message here"
}
- The API will respond with a success message and the Twilio message SID if the message was sent successfully.
By following these steps, you'll have a fully functional Text to Context Converter app that can analyze text through a web interface, WhatsApp, and API endpoints.