anushkap01patidar commited on
Commit ·
e573987
1
Parent(s): 80f43e1
Create minimal Gradio interface to test basic functionality: Remove all complex components and use only basic elements
Browse files- app.py +18 -104
- requirements.txt +9 -24
app.py
CHANGED
|
@@ -1,118 +1,32 @@
|
|
| 1 |
import os
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
-
import asyncio
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
from orchestrator.research_orchestrator import ResearchOrchestrator
|
| 7 |
-
from save_to_pdf import save_draft_to_pdf
|
| 8 |
-
|
| 9 |
-
|
| 10 |
# Load .env (for OPENAI_API_KEY)
|
| 11 |
load_dotenv()
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
async def run_workflow(topic: str):
|
| 22 |
-
if not topic.strip():
|
| 23 |
-
return "Please enter a topic.", "", "", ""
|
| 24 |
-
|
| 25 |
-
try:
|
| 26 |
-
orchestrator = ResearchOrchestrator()
|
| 27 |
-
result = await orchestrator.run(topic)
|
| 28 |
-
|
| 29 |
-
# Interrupted for outline review
|
| 30 |
-
if result.get("status") == "interrupted":
|
| 31 |
-
current_state = result.get("current_state", {})
|
| 32 |
-
outline = current_state.get("outline", "")
|
| 33 |
-
return "Outline generated. Review below.", outline, "", ""
|
| 34 |
-
|
| 35 |
-
# Completed directly (edge case)
|
| 36 |
-
if result.get("status") == "completed":
|
| 37 |
-
data = result.get("result", {})
|
| 38 |
-
draft = data.get("draft") or ""
|
| 39 |
-
pdf_path = f"data/{_safe_filename(data.get('refined_topic', topic))}.pdf"
|
| 40 |
-
os.makedirs("data", exist_ok=True)
|
| 41 |
-
try:
|
| 42 |
-
save_draft_to_pdf(data.get('refined_topic', topic), draft, data.get("bibliography", ""), pdf_path)
|
| 43 |
-
except Exception:
|
| 44 |
-
pdf_path = ""
|
| 45 |
-
return "Workflow completed.", draft, pdf_path, ""
|
| 46 |
-
|
| 47 |
-
# Error
|
| 48 |
-
return f"Error: {result.get('error', 'unknown')}", "", "", ""
|
| 49 |
-
|
| 50 |
-
except Exception as e:
|
| 51 |
-
return f"Error: {str(e)}", "", "", ""
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
async def resume_workflow(decision: str, feedback: str):
|
| 55 |
-
try:
|
| 56 |
-
# For now, return a simple message
|
| 57 |
-
if decision == "approve":
|
| 58 |
-
return "Outline approved. Generating draft...", "Draft will be generated here.", "", "Draft Preview"
|
| 59 |
-
elif decision == "revise":
|
| 60 |
-
return f"Revision requested: {feedback}", "Revised outline will appear here.", "", "Outline Preview"
|
| 61 |
-
else:
|
| 62 |
-
return "Workflow rejected.", "", "", "Output Preview"
|
| 63 |
-
except Exception as e:
|
| 64 |
-
return f"Error: {str(e)}", "", "", ""
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
# Create a simple interface
|
| 68 |
-
with gr.Blocks(title="Research Draft Generator") as demo:
|
| 69 |
-
gr.Markdown("# Research Draft Generator")
|
| 70 |
-
gr.Markdown("Enter a topic to generate a research paper outline and draft.")
|
| 71 |
-
|
| 72 |
-
with gr.Row():
|
| 73 |
topic = gr.Textbox(label="Topic", placeholder="e.g., Federated learning for healthcare")
|
| 74 |
start_btn = gr.Button("Generate Outline", variant="primary")
|
| 75 |
-
|
| 76 |
-
info = gr.Textbox(label="Status", interactive=False)
|
| 77 |
-
|
| 78 |
-
with gr.Row():
|
| 79 |
-
with gr.Column():
|
| 80 |
-
gr.Markdown("### Outline")
|
| 81 |
-
outline_display = gr.Textbox(label="Generated Outline", lines=10, interactive=False)
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
reject = gr.Button("Reject", variant="secondary")
|
| 92 |
-
|
| 93 |
-
pdf_output = gr.File(label="PDF Output")
|
| 94 |
-
|
| 95 |
-
# Wire actions
|
| 96 |
-
start_btn.click(
|
| 97 |
-
run_workflow,
|
| 98 |
-
inputs=[topic],
|
| 99 |
-
outputs=[info, outline_display, draft_display, pdf_output]
|
| 100 |
-
)
|
| 101 |
-
|
| 102 |
-
approve.click(
|
| 103 |
-
lambda: resume_workflow("approve", ""),
|
| 104 |
-
outputs=[info, outline_display, draft_display, pdf_output]
|
| 105 |
-
)
|
| 106 |
-
|
| 107 |
-
revise.click(
|
| 108 |
-
lambda: resume_workflow("revise", feedback.value),
|
| 109 |
-
outputs=[info, outline_display, draft_display, pdf_output]
|
| 110 |
-
)
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
|
| 117 |
# Launch the app for Hugging Face Spaces
|
| 118 |
port = int(os.getenv("PORT", 7860))
|
|
|
|
| 1 |
import os
|
| 2 |
from dotenv import load_dotenv
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# Load .env (for OPENAI_API_KEY)
|
| 6 |
load_dotenv()
|
| 7 |
|
| 8 |
+
def simple_interface():
|
| 9 |
+
"""Create the most basic possible Gradio interface"""
|
| 10 |
+
with gr.Blocks(title="Research Draft Generator") as demo:
|
| 11 |
+
gr.Markdown("# Research Draft Generator")
|
| 12 |
+
gr.Markdown("Enter a topic to generate a research paper outline and draft.")
|
| 13 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
topic = gr.Textbox(label="Topic", placeholder="e.g., Federated learning for healthcare")
|
| 15 |
start_btn = gr.Button("Generate Outline", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
output = gr.Textbox(label="Output", lines=10, interactive=False)
|
| 18 |
+
|
| 19 |
+
def process_topic(topic_text):
|
| 20 |
+
if not topic_text.strip():
|
| 21 |
+
return "Please enter a topic."
|
| 22 |
+
return f"Processing topic: {topic_text}\n\nThis is a placeholder response. The full functionality will be implemented once the interface is working."
|
| 23 |
+
|
| 24 |
+
start_btn.click(process_topic, inputs=[topic], outputs=[output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
return demo
|
| 27 |
+
|
| 28 |
+
# Create and launch the interface
|
| 29 |
+
demo = simple_interface()
|
| 30 |
|
| 31 |
# Launch the app for Hugging Face Spaces
|
| 32 |
port = int(os.getenv("PORT", 7860))
|
requirements.txt
CHANGED
|
@@ -1,25 +1,10 @@
|
|
| 1 |
gradio==4.43.0
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
langchain
|
| 12 |
-
openai
|
| 13 |
-
langchain-community
|
| 14 |
-
langchain-openai
|
| 15 |
-
anthropic
|
| 16 |
-
tiktoken
|
| 17 |
-
python-dotenv
|
| 18 |
-
requests
|
| 19 |
-
beautifulsoup4
|
| 20 |
-
markdown
|
| 21 |
-
fastapi
|
| 22 |
-
uvicorn
|
| 23 |
-
pydantic>=2
|
| 24 |
-
langgraph>=0.2.30
|
| 25 |
-
reportlab
|
|
|
|
| 1 |
gradio==4.43.0
|
| 2 |
+
langgraph>=0.2.0
|
| 3 |
+
langchain>=0.2.0
|
| 4 |
+
langchain-community>=0.2.0
|
| 5 |
+
langchain-openai>=0.2.0
|
| 6 |
+
langchain-core>=0.2.0
|
| 7 |
+
openai>=1.0.0
|
| 8 |
+
python-dotenv>=1.0.0
|
| 9 |
+
reportlab>=4.0.0
|
| 10 |
+
pydantic>=2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|