shoaibahmed912's picture
initial commit
89e6ffa verified
|
Raw History Blame Contribute Delete
3.45 kB
metadata
title: Transcript Extraction Backend
emoji: 📄
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860

Transcript Extraction Backend

FastAPI backend that accepts transcript uploads (jpg, jpeg, jpp, png, or pdf) and returns a structured JSON object with personal details, semesters, subjects, marks, credit hours, GPA, and CGPA where available.

The extraction path is deployable and free-tier friendly:

  • FastAPI receives a transcript file
  • Gemini reads the uploaded PDF/image directly
  • Gemini returns the normalized JSON response

Setup

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Create a local .env file:

GEMINI_API_KEY=your_gemini_api_key_here
GEMINI_MODEL=gemini-2.5-flash
FIREBASE_SERVICE_ACCOUNT_BASE64=base64_encoded_firebase_service_account_json
TEST_AUTH_TOKEN=local-test-token

Run

uvicorn app.main:app --reload

Open:

http://127.0.0.1:8000/docs

Extract Transcript

curl -X POST "http://127.0.0.1:8000/extract" \
  -H "Authorization: Bearer FIREBASE_ID_TOKEN_FROM_MOBILE_APP" \
  -F "file=@/path/to/transcript.pdf"

Firebase Authentication

The mobile app signs the user in with Firebase Auth, gets the user's ID token, and sends it to this backend:

Authorization: Bearer <firebase_id_token>

The backend verifies that token with Firebase Admin SDK before processing /extract.

For local Swagger testing only, set TEST_AUTH_TOKEN in .env, restart the server, and enter the same value in the test_auth_token parameter shown on /extract. Do not set TEST_AUTH_TOKEN in production.

To configure the backend, create a Firebase service account:

  1. Open Firebase Console.
  2. Go to Project settings.
  3. Open Service accounts.
  4. Generate a new private key.
  5. Convert the JSON file to base64 and put it into FIREBASE_SERVICE_ACCOUNT_BASE64 in .env locally or in your cloud host environment variables.

On macOS:

base64 -i firebase-service-account.json

Do not commit the service account JSON file or paste it into mobile app code.

Free Cloud LLM

For deployment, use the Gemini API free tier. Create an API key in Google AI Studio, then set it as an environment variable in your cloud host:

export GEMINI_API_KEY=your_api_key_here
export GEMINI_MODEL=gemini-2.5-flash
uvicorn app.main:app --reload

The backend sends the uploaded transcript file directly to Gemini and asks it to normalize the transcript into the response JSON schema. If Gemini is not configured, rate-limited, or returns invalid JSON, the API returns an error.

Deploy On Hugging Face Spaces

This repo includes a Dockerfile for Hugging Face Spaces deployment.

Create a new Space:

  1. Go to https://huggingface.co/spaces.
  2. Click Create new Space.
  3. Choose a name, for example transcript-data-backend.
  4. Choose Docker as the SDK.
  5. Choose CPU Basic.
  6. Create the Space.
  7. Upload or push this repository to the Space repo.

Add these as Space secrets:

GEMINI_API_KEY=your_gemini_key
GEMINI_MODEL=gemini-2.5-flash
FIREBASE_SERVICE_ACCOUNT_BASE64=base64_encoded_firebase_service_account_json

Do not set TEST_AUTH_TOKEN in production.

After the Space builds, open:

https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME

The API docs should be available at:

https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/docs