This application generates social media posts (Facebook, LinkedIn, X/Twitter, and Instagram) to feature Transportation Marketing and Sales Association (TMSA) member companies. It uses:
- Requests + BeautifulSoup for extracting homepage text,
- Ollama for local LLM inference (Llama 3.1), and
- Gradio for a user-friendly interface allowing up to 12 company/website entries at once.
When you run this app, each company gets a text file with four social media posts (one for each platform) in the output folder, according to TMSA’s branding and style guidelines.
- Python 3.11+.
- Ollama installed and configured on your Windows system, including the Llama 3.1 model (
llama3.1:latestor your preferred variant).- You can verify installation in the Windows terminal:
where ollama
- If
ollamais not on your PATH, add it or refer to Ollama’s documentation.
- You can verify installation in the Windows terminal:
- Basic Python environment with the following libraries installed:
requestsbeautifulsoup4gradio
-
Clone or download this repository.
-
In your command prompt (Windows) or terminal, navigate to the project directory and install the Python dependencies:
pip install requests beautifulsoup4 gradio ollama
-
Check if Ollama is properly installed and accessible:
where ollama
If not found, follow Ollama’s documentation to install and set up on Windows.
-
(Optional) Create and activate a virtual environment to keep dependencies isolated:
python -m venv venv venv\Scripts\activate pip install -r requirements.txt
-
Run the Application From your terminal, run:
python app.py
This launches a local Gradio interface (usually at
http://127.0.0.1:7860). -
Enter Company/Website Pairs
- In the Gradio app, enter up to 12 company names and their respective website URLs.
- Click Generate Posts.
-
Review Output
- For each valid
(Company Name, Website URL)pair, the app will:- Extract homepage text (using
requests+BeautifulSoup). - Generate four social media posts (Facebook, LinkedIn, X, Instagram) by calling Ollama sequentially.
- Save all four posts in a single text file named
{CompanyName_YYYYMMDD}.txtinside theoutputdirectory.
- Extract homepage text (using
- Progress and log messages appear in the Gradio textbox and in the
app.logfile.
- For each valid
-
Text Extraction:
- The code uses
requests.get()to fetch the homepage HTML andBeautifulSoupto parse it, extracting text from<p>and<h1>–<h6>tags. - If any error occurs (e.g., invalid URL, timeout), the process logs the error and skips that company.
- The code uses
-
Generating Social Media Posts:
- The script calls
ollama.chat()four times in sequence (Facebook, LinkedIn, X/Twitter, Instagram). - Each post uses unique prompts tailored for that social platform, combined with TMSA brand guidelines and a snippet of extracted homepage text.
- The app waits for each LLM response before moving on to the next.
- The script calls
-
Saving Output:
- The final text file for each company includes all four posts, labeled with the social network.
- By default, the files are placed in an
outputdirectory, which is created automatically if it doesn’t exist.
-
Ollama not found:
- Run
where ollamaon Windows. If it doesn’t show a path, ensure you’ve installed Ollama and added it to your PATH. - Confirm you have the correct Llama model:
llama3.1:latest. If different, update themodel_namevariable in the code.
- Run
-
Python library not installed:
- Run
pip show requests(orpip list | findstr requestson Windows). - If missing, run
pip install requests. Repeat forbeautifulsoup4,gradio, etc.
- Run
-
Time out / Connection errors:
- Some websites or restrictive network environments can lead to timeouts. Increase
timeoutinrequests.get(url, timeout=10)or try again later.
- Some websites or restrictive network environments can lead to timeouts. Increase
-
Large Webpages / Long Summaries:
- The code currently truncates homepage text to the first 1500 characters. Adjust this in
shortened_homepage_context = homepage_text[:1500]if needed.
- The code currently truncates homepage text to the first 1500 characters. Adjust this in
-
Output not appearing:
- Check your
outputfolder. - Check
app.logfor any error messages.
- Check your
This project is provided via the MIT license. It is intended as a demonstration for creating a local AI agent application with Ollama, requests, BeautifulSoup, and Gradio.
Feel free to adapt or expand this code for your own internal or commercial use, abiding by any relevant licensing.