import gradio as gr from openai import OpenAI import os ACCESS_TOKEN = os.getenv("HF_TOKEN") client = OpenAI( base_url="https://api-inference.huggingface.co/v1/", api_key=ACCESS_TOKEN, ) *def* *generate_study_material*( topic, difficulty, question_type, focus_areas, anxiety_level, num_questions ): # Customize prompt based on anxiety level and learning focus anxiety_prompts = { "High": "Create a gradual, confidence-building set of questions. Start with easier concepts and progressively increase difficulty. Include encouraging notes.", "Medium": "Balance challenge with achievability. Include hints for tougher questions and positive reinforcement.", "Low": "Focus on comprehensive concept testing while maintaining an encouraging tone." } focus_prompt = { "concept_understanding": "Emphasize questions that test deep understanding rather than memorization.", "problem_solving": "Include scenario-based questions that require analytical thinking.", "quick_recall": "Focus on key definitions and fundamental concepts.", "practical_application": "Create questions based on real-world applications." } base_prompt = f""" Act as an expert educational psychologist and subject matter expert creating an exam preparation guide. Topic: {topic} Difficulty: {difficulty} Question Type: {question_type} Number of Questions: {num_questions} Special Considerations: - Anxiety Level: {anxiety_level} {anxiety_prompts[anxiety_level]} - Learning Focus: {focus_areas} {focus_prompt[focus_areas]} Generate questions following these guidelines: 1. Start with a brief confidence-building message 2. Include clear, unambiguous questions 3. Provide detailed explanations for each answer 4. Add study tips relevant to the topic 5. Include a "Remember" section with key points Format: - For Multiple Choice: Include 4 options with explanations for each - For Short Answer: Provide structure hints and model answers - For Descriptive: Break down marking criteria and include outline points Additional Requirements: - Include think-aloud strategies for problem-solving - Add time management suggestions - Highlight common misconceptions to avoid - End with a positive reinforcement message """ *try*: messages = [ {"role": "system", "content": "You are an expert educational content generator."}, {"role": "user", "content": base_prompt} ] response = client.chat.completions.create( model="Qwen/QwQ-32B-Preview", messages=messages, max_tokens=2048, temperature=0.7, top_p=0.9 ) *return* response.choices[0].message.content *except* *Exception* *as* e: *return* f"An error occurred: {*str*(e)}\nPlease try again with different parameters." *def* *create_interface*(): *with* gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) *as* iface: gr.Markdown(""" #