Building a Django Web App with Gemini API and Hugging Face for Text Simplification

Recently I was involved in Project that touches a least use case, I’m writing this tutorial to you through building a Django web application that simplifies complex English text using a combination of Hugging Face Transformers (for local models) and Google’s Gemini API (for advanced AI reasoning).

🧠 Use Case: Text Simplification for Non-Native English Speakers

This use case is particularly useful for students, language learners, or professionals needing to understand dense academic or technical texts.


βœ… Prerequisites

Before we begin, ensure the following are installed:

  1. Python 3.8+
  2. pip
  3. Virtual environment (venv)
  4. Django
  5. Git (optional)

πŸ“¦ Tools & Services Used

Tool/ServicePurpose
DjangoBackend web framework
Hugging FaceLocal NLP model inference
Gemini APICloud-based advanced summarization
PostgreSQL (or SQLite)Database for storing history

πŸš€ Step-by-Step Implementation


πŸ“ Step 1: Set Up Your Project

Install dependencies:

Start a new Django project:

Add app to INSTALLED_APPS in simplifier_project/settings.py:

Apply migrations:


πŸ—‚οΈ Step 2: Create Models

In simplifier_app/models.py, define a model to store user input and results:

Run migrations:


πŸ” Step 3: Configure Gemini API Key

Create .env file at root:

Update simplifier_project/settings.py to load it:


πŸ€– Step 4: Add Hugging Face and Gemini Logic

Create a utility file utils.py inside simplifier_app:


🌐 Step 5: Build Views and Templates

In views.py:


πŸ“„ Step 6: Create HTML Templates

Create a folder templates/ in the project root and add:

templates/simplify_form.html

templates/history.html


🧭 Step 7: Configure URLs

In simplifier_app/urls.py:

In simplifier_project/urls.py:

Set templates directory in settings.py:


πŸƒβ€β™‚οΈ Step 8: Run Server and Test

Open browser at http://localhost:8000

Try pasting a complex paragraph like:

“The process of photosynthesis involves the green pigmentation within chloroplasts capturing light energy, which subsequently facilitates the conversion of carbon dioxide and water into glucose and oxygen.”

Choose either Hugging Face or Gemini, then submit. You’ll be redirected to the simplified version and history page.


πŸ“ˆ Optional Enhancements

  • Add user authentication to track per-user history
  • Allow document uploads (.txt, .pdf)
  • Cache frequent queries
  • Add comparison between both methods
  • Deploy on Vercel + Hugging Face Inference API

πŸ§ͺ Sample Output Comparison

Input:

“Photosynthesis is a process used by plants and other organisms to convert light energy into chemical energy.”

Hugging Face BART Output:

“Photosynthesis helps plants change light into energy.”

Gemini Output:

“Plants use sunlight to make food through a process called photosynthesis.”


πŸ“¦ Deployment Tips

Use gunicorn and whitenoise for production:

Deploy via:

  • Heroku
  • Render
  • Railway
  • Docker + AWS/GCP

🧠 Why This Use Case?

While most apps focus on translation or summarization, text simplification for ESL (English as Second Language) users is an underutilized but highly impactful task. It helps improve accessibility and comprehension across diverse educational and professional backgrounds.


βœ… Summary

You now have a full-stack Django app that leverages:

  • Hugging Face Transformers for fast, offline text simplification
  • Google Gemini API for more nuanced AI-generated explanations
  • A simple UI for interaction and history tracking

This architecture can easily scale into a larger NLP service hub!


πŸ™‹β€β™‚οΈ Further scope of work

  • Admin panel customization
  • PDF upload support
  • REST API version
  • Multilingual support

Happy coding! πŸš€

Previous Article

Understanding AI MCP (Model Context Protocol): A Beginner’s Guide

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨