from flask import Flask, request, jsonify from flask_cors import CORS import fitz import requests import os app = Flask(__name__) CORS(app) # Enable CORS HF_API_KEY = os.getenv("HF_API_KEY") # <-- From Hugging Face secret MODEL_ENDPOINT = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1" def extract_text_from_pdf(file_stream): try: doc = fitz.open(stream=file_stream.read(), filetype="pdf") text = "" for page in doc: text += page.get_text() if len(text) > 1500: break return text.strip() except Exception as e: print("❌ Error extracting PDF:", e) return None def generate_mcqs(text): prompt = f""" You are an expert teacher. Given the following content, generate 30 well-structured multiple-choice questions. Each question must have: 1. A clear question 2. 4 options (A, B, C, D) 3. The correct answer letter Format the output as: Q1: A.