import gradio as gr import os import sys import warnings # Suppress benign warnings from dependencies (like Starlette) warnings.filterwarnings("ignore") # Add current directory to path so imports work correctly sys.path.append(os.path.abspath(os.path.dirname(__file__))) from preprocessing.process_pipeline import generate_mcq_pipeline def process_text(passage): if not passage.strip(): return "⚠️ Please enter some Tamil text first!", [] # Split the text into sentences sentences = [s.strip() for s in passage.replace("!", ".").replace("?", ".").split(".") if s.strip()] mcq_list = [] for sentence in sentences: try: # Run the pipeline res = generate_mcq_pipeline(sentence) if res and res.get("question") and len(res.get("options", [])) >= 4: mcq_list.append(res) except Exception as e: print(f"Error processing sentence '{sentence}': {e}") pass if not mcq_list: return "ℹ️ No suitable sentences found for MCQ generation. Try a longer, more descriptive paragraph.", [] return f"✅ Successfully generated {len(mcq_list)} MCQs!", mcq_list default_text = """சாதி அடிப்படையிலான அரசியல் இயக்கங்கள் மற்றும் அவற்றின் தாக்கம் குறித்து விரிவாக பார்க்கும்போது, தமிழ்நாட்டின் அரசியல் பரிணாமம் பல்வேறு சமூக, மொழி மற்றும் பொருளாதார காரணிகளால் வடிவமைக்கப்பட்டுள்ளது. இந்த அமைப்பில் தேர்தல் ஆணையத்தின் கட்டுப்பாடுகள், தொகுதி மறுசீரமைப்புகள், மற்றும் வாக்காளர் பதிவுகள் ஆகியவை குறிப்பிடத்தக்கவை. சட்டமன்றத்தில் நிறைவேற்றப்படும் மசோதாக்கள் பொதுவாக குழு ஆய்வுகள் மற்றும் விவாதங்களின் மூலம் மாற்றங்களுடன் நிறைவேற்றப்படுகின்றன. நிர்வாகத் துறைகள் அமைச்சரவை முடிவுகளின் அடிப்படையில் செயல்படுகின்றன மற்றும் ஒவ்வொரு துறைக்கும் தனிப்பட்ட செயல்முறை விதிகள் உள்ளன. அரசியல் கட்சிகள் தங்களது தேர்தல் அறிக்கைகளில் குறிப்பிட்ட நலத்திட்டங்களை முன்வைத்து வாக்காளர்களை அணுகுகின்றன.""" with gr.Blocks(title="Tamil Question Answering App") as demo: gr.HTML("""
Generate interactive questions from text and answer them!