import gradio as gr from transformers import pipeline # Load the pre-trained model for generating formulas model_name = "gpt2" # Or you can choose a better model like a physics-specific fine-tuned model if available generator = pipeline("text-generation", model=model_name) # Function to generate mathematical formulas based on physics topic def generate_formulas(physics_topic): prompt = f"List the important mathematical formulas related to {physics_topic} in physics." # Generate the formulas using the model formulas = generator(prompt, max_length=200, num_return_sequences=1) return formulas[0]["generated_text"] # Create Gradio interface interface = gr.Interface( fn=generate_formulas, inputs=gr.Textbox(label="Enter a Physics Topic", placeholder="e.g. Newton's Laws, Thermodynamics, etc."), outputs="text", title="Physics Formula Generator", description="Enter a physics-related topic, and the tool will generate important mathematical formulas related to that topic." ) # Launch the Gradio app interface.launch(share=True)