Spaces:
Sleeping
Sleeping
File size: 2,362 Bytes
243a67a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
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() |