File size: 3,564 Bytes
1561d5f
 
73dd1a1
1561d5f
 
 
 
e573987
a656e6b
e573987
 
 
 
a656e6b
6e97bd9
a656e6b
80f43e1
a656e6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e573987
 
 
a656e6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e573987
a656e6b
 
 
 
 
80f43e1
e573987
 
 
 
1561d5f
a80913a
 
 
 
 
 
 
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
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
from dotenv import load_dotenv
import gradio as gr

# Load .env (for OPENAI_API_KEY)
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.", "", ""
            
            # Simulate the workflow steps
            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.", "", ""
        
        # Wire the events
        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

# Create and launch the interface
demo = simple_interface()

# Launch the app for Hugging Face Spaces
port = int(os.getenv("PORT", 7860))
demo.launch(
    server_name="0.0.0.0",
    server_port=port,
    show_error=True
)