|
|
import os |
|
|
from dotenv import load_dotenv |
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
def simple_interface(): |
|
|
"""Create a working Gradio interface with basic workflow functionality""" |
|
|
with gr.Blocks(title="Research Draft Generator") as demo: |
|
|
gr.Markdown("# Research Draft Generator") |
|
|
gr.Markdown("Enter a topic to generate a research paper outline and draft.") |
|
|
|
|
|
with gr.Row(): |
|
|
topic = gr.Textbox(label="Topic", value="e.g., Federated learning for healthcare") |
|
|
start_btn = gr.Button("Generate Outline", variant="primary") |
|
|
|
|
|
status = gr.Textbox(label="Status", interactive=False) |
|
|
|
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
gr.Markdown("### Generated Outline") |
|
|
outline_display = gr.Textbox(label="Outline", lines=8, interactive=False) |
|
|
|
|
|
with gr.Column(): |
|
|
gr.Markdown("### Generated Draft") |
|
|
draft_display = gr.Textbox(label="Draft", lines=8, interactive=False) |
|
|
|
|
|
with gr.Row(): |
|
|
feedback = gr.Textbox(label="Revision feedback", placeholder="What should be improved?") |
|
|
approve = gr.Button("Approve", variant="primary") |
|
|
revise = gr.Button("Request Revision") |
|
|
reject = gr.Button("Reject", variant="secondary") |
|
|
|
|
|
def process_topic(topic_text): |
|
|
if not topic_text.strip(): |
|
|
return "Please enter a topic.", "", "" |
|
|
|
|
|
|
|
|
status_msg = f"Processing topic: {topic_text}" |
|
|
outline = f"""# Research Outline: {topic_text} |
|
|
|
|
|
## 1. Introduction |
|
|
- Background and motivation |
|
|
- Problem statement |
|
|
- Research objectives |
|
|
|
|
|
## 2. Literature Review |
|
|
- Current state of research |
|
|
- Key methodologies |
|
|
- Gaps in existing work |
|
|
|
|
|
## 3. Methodology |
|
|
- Research approach |
|
|
- Data collection methods |
|
|
- Analysis techniques |
|
|
|
|
|
## 4. Expected Results |
|
|
- Anticipated findings |
|
|
- Potential contributions |
|
|
- Future research directions |
|
|
|
|
|
*This is a generated outline. Click 'Approve' to generate the full draft, or 'Request Revision' to modify.*""" |
|
|
|
|
|
draft = "" |
|
|
return status_msg, outline, draft |
|
|
|
|
|
def approve_outline(): |
|
|
return "Outline approved! Generating full draft...", "", "Full research paper draft will be generated here. This feature will be implemented once the basic interface is fully stable." |
|
|
|
|
|
def request_revision(feedback_text): |
|
|
if not feedback_text.strip(): |
|
|
feedback_text = "general improvements" |
|
|
return f"Revision requested: {feedback_text}", "Revised outline will be generated here based on your feedback.", "" |
|
|
|
|
|
def reject_outline(): |
|
|
return "Outline rejected. Please start over with a new topic.", "", "" |
|
|
|
|
|
|
|
|
start_btn.click(process_topic, inputs=[topic], outputs=[status, outline_display, draft_display]) |
|
|
approve.click(approve_outline, outputs=[status, outline_display, draft_display]) |
|
|
revise.click(request_revision, inputs=[feedback], outputs=[status, outline_display, draft_display]) |
|
|
reject.click(reject_outline, outputs=[status, outline_display, draft_display]) |
|
|
|
|
|
return demo |
|
|
|
|
|
|
|
|
demo = simple_interface() |
|
|
|
|
|
|
|
|
port = int(os.getenv("PORT", 7860)) |
|
|
demo.launch( |
|
|
server_name="0.0.0.0", |
|
|
server_port=port, |
|
|
show_error=True |
|
|
) |
|
|
|