import gradio as gr import os from dotenv import load_dotenv from crew import get_crew import threading # Load environment variables load_dotenv() # Global lock for thread safety lock = threading.Lock() VERBOSE = False def invoke(topic): """Generate scientific paper based on the topic""" if not topic: raise gr.Error("Topic is required.") with lock: # Generate the paper crew = get_crew(verbose=VERBOSE, topic=topic) paper = str(crew.kickoff()) return paper # Create the Gradio interface css = """ .gradio-container { font-family: 'Arial', sans-serif; } .paper-output { font-size: 16px; line-height: 1.6; padding: 20px; background: #f9f9f9; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } """ demo = gr.Interface( fn=invoke, inputs=[ gr.Textbox( label="Research Topic", placeholder="Enter your research topic...", lines=2 ) ], outputs=[ gr.Markdown( label="Generated Scientific Paper", elem_classes="paper-output" ) ], title="AI Scientific Paper Generator", description="""This application uses AI agents to generate comprehensive scientific papers. The first agent researches your topic using PubMed Central and Google Scholar, collecting at least 20 relevant articles. The second agent then synthesizes this research into a well-structured scientific paper with proper citations. Created by Dr. Fernando Ly""", article="""### How it works 1. Enter your research topic 2. The Research Agent will collect relevant scientific articles 3. The Writing Agent will generate a structured paper with: - Introduction - Materials and Methods - Results - Discussion - Conclusion - References (APA format) The paper will include proper citations and be based on real scientific literature.""", css=css, theme=gr.themes.Soft( primary_hue="blue", secondary_hue="gray" ) ) # Launch the app if __name__ == "__main__": demo.launch()