import gradio as gr # TOOL: Study Helper def study_helper(subject: str) -> str: """ A tool that provides study tips for different subjects. Args: subject: The school subject the student needs help with. """ subject = subject.lower() if "math" in subject: return "Math Tip: Practice formulas and solve problems step by step." elif "science" in subject: return "Science Tip: Focus on understanding concepts and vocabulary." elif "history" in subject: return "History Tip: Create timelines and remember important events." elif "english" in subject: return "English Tip: Practice reading comprehension and grammar." else: return "Try asking about math, science, history, or English." # AGENT: Think -> Action -> Observation def agent(user_input: str) -> str: # THINK: Understand the user's request subject = user_input.lower().strip() # ACTION: Call the study helper tool result = study_helper(subject) # OBSERVATION: Return the tool's result return result # Create the interactive interface demo = gr.Interface( fn=agent, inputs=gr.Textbox( label="Your Question", placeholder="Example: Help me study math" ), outputs=gr.Textbox(label="Agent Response"), title="AI Study Helper Agent", description="A Python-based study helper that provides tips for different school subjects.", examples=[ ["Help me study math"], ["Help me study science"], ["Help me study history"], ["Help me study English"] ] ) # Launch the application demo.launch()