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InferenceClient
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
# Initialize the Llama 3.3 model client with Cerebras provider
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
client = InferenceClient(
|
| 11 |
+
"meta-llama/Llama-3.3-70B-Instruct",
|
| 12 |
+
provider="cerebras",
|
| 13 |
+
token=os.getenv("HF_TOKEN"),
|
| 14 |
+
)
|
| 15 |
+
except Exception as e:
|
| 16 |
+
print(f"Error initializing Cerebras client: {e}")
|
| 17 |
+
# Fallback to default provider
|
| 18 |
+
client = InferenceClient("meta-llama/Llama-3.3-70B-Instruct")
|
| 19 |
+
|
| 20 |
+
# Turabian-based prompts for each stage
|
| 21 |
+
TURABIAN_PROMPTS = {
|
| 22 |
+
"stage_1_commonsense": """Based on Turabian's method for developing research arguments, analyze this topic and create a commonsense argument with:
|
| 23 |
+
|
| 24 |
+
1. A clear main CLAIM (what you're arguing)
|
| 25 |
+
2. 2-3 supporting REASONS (why readers should accept your claim)
|
| 26 |
+
3. Types of EVIDENCE needed (what would support your reasons)
|
| 27 |
+
4. Present it as everyday conversation logic
|
| 28 |
+
|
| 29 |
+
Make it simple and foundational - this is just the starting point.
|
| 30 |
+
|
| 31 |
+
Topic: {input}
|
| 32 |
+
|
| 33 |
+
Format your response as:
|
| 34 |
+
CLAIM: [Your main argument]
|
| 35 |
+
REASON 1: [First supporting reason]
|
| 36 |
+
REASON 2: [Second supporting reason]
|
| 37 |
+
REASON 3: [Third reason if needed]
|
| 38 |
+
EVIDENCE TYPES NEEDED: [What kind of evidence you'd need]""",
|
| 39 |
+
|
| 40 |
+
"stage_2_transition": """Help transition this commonsense argument into a research argument framework suitable for academic writing:
|
| 41 |
+
|
| 42 |
+
1. Identify what needs strengthening for a scholarly audience
|
| 43 |
+
2. Note areas requiring more formal evidence
|
| 44 |
+
3. Suggest how to frame this as a cooperative conversation with skeptical but receptive colleagues
|
| 45 |
+
4. Highlight the gap between commonsense and research-level argumentation
|
| 46 |
+
|
| 47 |
+
Current Commonsense Argument: {input}
|
| 48 |
+
|
| 49 |
+
Format your response with:
|
| 50 |
+
STRENGTHS TO BUILD ON: [What's already strong]
|
| 51 |
+
AREAS NEEDING DEVELOPMENT: [What needs more work]
|
| 52 |
+
ACADEMIC FRAMING: [How to present to scholars]
|
| 53 |
+
NEXT STEPS: [What to focus on in Stage 3]""",
|
| 54 |
+
|
| 55 |
+
"stage_3a_claim": """Transform this working hypothesis into a specific, supportable academic claim:
|
| 56 |
+
|
| 57 |
+
1. Make it an assertion that clearly demands support
|
| 58 |
+
2. Ensure it's specific and focused (not too broad)
|
| 59 |
+
3. Check that you can realistically support it with available evidence
|
| 60 |
+
4. Make sure it goes beyond obvious or trivial statements
|
| 61 |
+
|
| 62 |
+
Working Hypothesis: {input}
|
| 63 |
+
|
| 64 |
+
Provide:
|
| 65 |
+
REFINED CLAIM: [Your specific, supportable claim]
|
| 66 |
+
WHY THIS WORKS: [Why this claim is effective]
|
| 67 |
+
POTENTIAL CHALLENGES: [What might be difficult to prove]
|
| 68 |
+
SCOPE NOTES: [What you're including/excluding]""",
|
| 69 |
+
|
| 70 |
+
"stage_3b_evidence": """Develop comprehensive reasons and evidence strategy for this claim:
|
| 71 |
+
|
| 72 |
+
1. Generate multiple strong supporting reasons
|
| 73 |
+
2. Identify primary source evidence needed
|
| 74 |
+
3. Assess evidence quality, quantity, and type requirements
|
| 75 |
+
4. Note potential challenges readers might raise about your evidence
|
| 76 |
+
|
| 77 |
+
Claim: {input}
|
| 78 |
+
|
| 79 |
+
Provide:
|
| 80 |
+
REASON 1: [First major reason]
|
| 81 |
+
- Evidence needed: [Specific evidence for this reason]
|
| 82 |
+
REASON 2: [Second major reason]
|
| 83 |
+
- Evidence needed: [Specific evidence for this reason]
|
| 84 |
+
REASON 3: [Third reason if applicable]
|
| 85 |
+
- Evidence needed: [Specific evidence for this reason]
|
| 86 |
+
PRIMARY SOURCES REQUIRED: [What original sources you need]
|
| 87 |
+
EVIDENCE QUALITY STANDARDS: [What makes strong evidence here]
|
| 88 |
+
POTENTIAL EVIDENCE CHALLENGES: [What readers might question]""",
|
| 89 |
+
|
| 90 |
+
"stage_3c_objections": """Anticipate objections and questions from careful, skeptical readers:
|
| 91 |
+
|
| 92 |
+
1. List questions skeptical readers might ask
|
| 93 |
+
2. Identify internal soundness challenges (evidence quality, reason consistency)
|
| 94 |
+
3. Identify external soundness challenges (alternative views, exceptions)
|
| 95 |
+
4. Suggest strong responses to key objections
|
| 96 |
+
|
| 97 |
+
Argument: {input}
|
| 98 |
+
|
| 99 |
+
Provide:
|
| 100 |
+
READER QUESTIONS: [What will they ask?]
|
| 101 |
+
INTERNAL CHALLENGES: [Questions about evidence/logic]
|
| 102 |
+
EXTERNAL CHALLENGES: [Alternative interpretations/views]
|
| 103 |
+
KEY OBJECTION 1: [Most important objection]
|
| 104 |
+
- Your Response: [How you'll address it]
|
| 105 |
+
KEY OBJECTION 2: [Second most important]
|
| 106 |
+
- Your Response: [How you'll address it]
|
| 107 |
+
ACKNOWLEDGMENT STRATEGY: [How to show you've considered these]""",
|
| 108 |
+
|
| 109 |
+
"stage_3d_warrants": """Identify and articulate the warrants (underlying principles) connecting your reasons to your claim:
|
| 110 |
+
|
| 111 |
+
1. Explain the underlying principles/assumptions
|
| 112 |
+
2. Create clear When-Then statements
|
| 113 |
+
3. Check if readers will likely accept these warrants
|
| 114 |
+
4. Note any limiting conditions
|
| 115 |
+
|
| 116 |
+
Reason: {reason}
|
| 117 |
+
Claim: {claim}
|
| 118 |
+
|
| 119 |
+
Provide:
|
| 120 |
+
UNDERLYING PRINCIPLE: [The basic assumption connecting reason to claim]
|
| 121 |
+
WHEN-THEN STATEMENT: [When X, then Y format]
|
| 122 |
+
WARRANT ACCEPTABILITY: [Will readers accept this principle?]
|
| 123 |
+
POTENTIAL WARRANT CHALLENGES: [What if readers question the principle?]
|
| 124 |
+
LIMITING CONDITIONS: [When might this warrant not apply?]
|
| 125 |
+
MAKING IT EXPLICIT: [How to clearly state this in your argument]""",
|
| 126 |
+
|
| 127 |
+
"stage_4a_storyboard": """Create a comprehensive storyboard/outline including all argument elements:
|
| 128 |
+
|
| 129 |
+
1. Research question
|
| 130 |
+
2. Working hypothesis/claim
|
| 131 |
+
3. Reasons and evidence
|
| 132 |
+
4. Acknowledgments and responses
|
| 133 |
+
5. Warrants
|
| 134 |
+
|
| 135 |
+
Argument Elements: {input}
|
| 136 |
+
|
| 137 |
+
Create:
|
| 138 |
+
RESEARCH QUESTION: [Your driving question]
|
| 139 |
+
MAIN CLAIM: [Your central argument]
|
| 140 |
+
STORYBOARD OUTLINE:
|
| 141 |
+
1. Introduction
|
| 142 |
+
- Hook/Context
|
| 143 |
+
- Research Question
|
| 144 |
+
- Claim Preview
|
| 145 |
+
2. Reason 1 + Evidence
|
| 146 |
+
- Warrant
|
| 147 |
+
- Potential Objection + Response
|
| 148 |
+
3. Reason 2 + Evidence
|
| 149 |
+
- Warrant
|
| 150 |
+
- Potential Objection + Response
|
| 151 |
+
4. [Additional reasons as needed]
|
| 152 |
+
5. Conclusion
|
| 153 |
+
- Claim Restatement
|
| 154 |
+
- Broader Implications
|
| 155 |
+
FLOW CHECK: [How sections connect logically]""",
|
| 156 |
+
|
| 157 |
+
"stage_4b_organization": """Organize this argument structure to meet reader needs and expectations:
|
| 158 |
+
|
| 159 |
+
1. Suggest optimal ordering strategies
|
| 160 |
+
2. Recommend transitional structure
|
| 161 |
+
3. Consider what academic readers expect
|
| 162 |
+
4. Plan logical flow between sections
|
| 163 |
+
|
| 164 |
+
Argument Elements: {input}
|
| 165 |
+
|
| 166 |
+
Provide:
|
| 167 |
+
RECOMMENDED ORGANIZATION: [Best structure approach]
|
| 168 |
+
- Chronological / Topical / Simple-to-Complex / etc.
|
| 169 |
+
SECTION ORDER: [Specific sequence]
|
| 170 |
+
TRANSITIONAL STRATEGY: [How sections will connect]
|
| 171 |
+
READER EXPECTATIONS: [What readers need to see when]
|
| 172 |
+
LOGICAL FLOW NOTES: [Why this order works]
|
| 173 |
+
ALTERNATIVE APPROACHES: [Other viable structures]""",
|
| 174 |
+
|
| 175 |
+
"stage_4c_intro_conclusion": """Sketch working introduction and conclusion that effectively frame your argument:
|
| 176 |
+
|
| 177 |
+
1. Draft introduction that hooks readers and previews argument
|
| 178 |
+
2. Draft conclusion that reinforces argument and shows significance
|
| 179 |
+
3. Ensure they work together as a frame
|
| 180 |
+
|
| 181 |
+
Main Argument: {input}
|
| 182 |
+
|
| 183 |
+
Create:
|
| 184 |
+
INTRODUCTION DRAFT:
|
| 185 |
+
- Opening Hook: [Engaging start]
|
| 186 |
+
- Context/Background: [Essential background]
|
| 187 |
+
- Research Question: [Your driving question]
|
| 188 |
+
- Claim Statement: [Clear claim]
|
| 189 |
+
- Roadmap: [What's coming]
|
| 190 |
+
|
| 191 |
+
CONCLUSION DRAFT:
|
| 192 |
+
- Claim Restatement: [Reaffirm your argument]
|
| 193 |
+
- Key Evidence Summary: [Main support]
|
| 194 |
+
- Broader Implications: [Why it matters]
|
| 195 |
+
- Future Research: [What's next]
|
| 196 |
+
|
| 197 |
+
FRAME COHERENCE: [How intro and conclusion work together]""",
|
| 198 |
+
|
| 199 |
+
"stage_4d_key_terms": """Identify and define key terms that will provide conceptual coherence throughout your paper:
|
| 200 |
+
|
| 201 |
+
1. Select terms representing core concepts
|
| 202 |
+
2. Ensure terms will run consistently through the paper
|
| 203 |
+
3. Check for conceptual clarity and consistency
|
| 204 |
+
|
| 205 |
+
Argument: {input}
|
| 206 |
+
|
| 207 |
+
Provide:
|
| 208 |
+
KEY TERMS TO DEFINE:
|
| 209 |
+
1. [Term 1]: [Definition and importance]
|
| 210 |
+
2. [Term 2]: [Definition and importance]
|
| 211 |
+
3. [Term 3]: [Definition and importance]
|
| 212 |
+
[Continue as needed]
|
| 213 |
+
|
| 214 |
+
CONCEPTUAL CONSISTENCY: [How terms relate to each other]
|
| 215 |
+
DEFINITION STRATEGY: [Where/how to define terms]
|
| 216 |
+
USAGE GUIDELINES: [How to use terms consistently]
|
| 217 |
+
POTENTIAL CONFUSION: [Terms readers might misunderstand]""",
|
| 218 |
+
|
| 219 |
+
"stage_5_drafting": """Provide comprehensive drafting guidance and best practices:
|
| 220 |
+
|
| 221 |
+
1. Effective writing habits
|
| 222 |
+
2. Source integration techniques
|
| 223 |
+
3. Evidence relevance demonstration
|
| 224 |
+
4. Using headings and key terms effectively
|
| 225 |
+
|
| 226 |
+
Writing Plan: {input}
|
| 227 |
+
|
| 228 |
+
Guidance:
|
| 229 |
+
WRITING HABITS:
|
| 230 |
+
- Daily writing schedule suggestions
|
| 231 |
+
- Productivity techniques
|
| 232 |
+
- Dealing with writer's block
|
| 233 |
+
|
| 234 |
+
SOURCE INTEGRATION:
|
| 235 |
+
- When to quote vs. paraphrase vs. summarize
|
| 236 |
+
- How to introduce sources effectively
|
| 237 |
+
- Attribution best practices
|
| 238 |
+
|
| 239 |
+
EVIDENCE CONNECTION:
|
| 240 |
+
- Making evidence relevance clear
|
| 241 |
+
- Linking evidence to reasons and claims
|
| 242 |
+
- Handling complex or detailed evidence
|
| 243 |
+
|
| 244 |
+
STRUCTURE MAINTENANCE:
|
| 245 |
+
- Using headings effectively
|
| 246 |
+
- Tracking key terms
|
| 247 |
+
- Maintaining argument thread
|
| 248 |
+
|
| 249 |
+
DRAFTING TIPS: [Practical writing advice]""",
|
| 250 |
+
|
| 251 |
+
"stage_6_revision": """Create a comprehensive revision checklist based on Turabian's standards:
|
| 252 |
+
|
| 253 |
+
1. Check for argument blind spots
|
| 254 |
+
2. Review introduction, conclusion, and claim clarity
|
| 255 |
+
3. Assess overall body coherence
|
| 256 |
+
4. Provide paragraph-level revision guidance
|
| 257 |
+
|
| 258 |
+
Draft Description: {input}
|
| 259 |
+
|
| 260 |
+
Revision Checklist:
|
| 261 |
+
|
| 262 |
+
ARGUMENT STRENGTH:
|
| 263 |
+
β‘ Blind spots check (unconsidered counterarguments?)
|
| 264 |
+
β‘ Alternative interpretations addressed?
|
| 265 |
+
β‘ Evidence gaps filled?
|
| 266 |
+
|
| 267 |
+
STRUCTURAL CLARITY:
|
| 268 |
+
β‘ Introduction clearly frames argument?
|
| 269 |
+
β‘ Conclusion reinforces without repeating?
|
| 270 |
+
β‘ Claim visible and specific?
|
| 271 |
+
|
| 272 |
+
BODY COHERENCE:
|
| 273 |
+
β‘ Key terms used consistently?
|
| 274 |
+
β‘ Section breaks logical?
|
| 275 |
+
β‘ Each section contributes to main argument?
|
| 276 |
+
β‘ Transitions smooth and clear?
|
| 277 |
+
|
| 278 |
+
PARAGRAPH LEVEL:
|
| 279 |
+
β‘ Each paragraph has clear purpose?
|
| 280 |
+
β‘ Evidence clearly supports reasons?
|
| 281 |
+
β‘ Warrants made explicit where needed?
|
| 282 |
+
|
| 283 |
+
REVISION PRIORITIES: [What to focus on first]"""
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
# Track user progress through stages
|
| 287 |
+
def get_stage_info(stage_key):
|
| 288 |
+
stage_info = {
|
| 289 |
+
"stage_1": {"name": "Commonsense Argument", "description": "Create your foundational argument"},
|
| 290 |
+
"stage_2": {"name": "Research Transition", "description": "Move from commonsense to academic"},
|
| 291 |
+
"stage_3a": {"name": "Claim Development", "description": "Refine your specific claim"},
|
| 292 |
+
"stage_3b": {"name": "Evidence Mapping", "description": "Plan reasons and evidence"},
|
| 293 |
+
"stage_3c": {"name": "Objection Analysis", "description": "Anticipate reader challenges"},
|
| 294 |
+
"stage_3d": {"name": "Warrant Identification", "description": "Connect reasons to claims"},
|
| 295 |
+
"stage_4a": {"name": "Storyboard Creation", "description": "Outline your argument"},
|
| 296 |
+
"stage_4b": {"name": "Organization Planning", "description": "Structure for readers"},
|
| 297 |
+
"stage_4c": {"name": "Introduction & Conclusion", "description": "Frame your argument"},
|
| 298 |
+
"stage_4d": {"name": "Key Terms", "description": "Define core concepts"},
|
| 299 |
+
"stage_5": {"name": "Drafting Guidance", "description": "Write your first draft"},
|
| 300 |
+
"stage_6": {"name": "Revision Checklist", "description": "Polish your argument"}
|
| 301 |
+
}
|
| 302 |
+
return stage_info.get(stage_key, {"name": "Unknown", "description": ""})
|
| 303 |
+
|
| 304 |
+
# Main processing function
|
| 305 |
+
@spaces.GPU
|
| 306 |
+
def process_stage(stage, input_text, reason_text="", claim_text=""):
|
| 307 |
+
"""Process input through selected Turabian stage"""
|
| 308 |
+
|
| 309 |
+
if not input_text.strip():
|
| 310 |
+
return "Please provide input text to analyze."
|
| 311 |
+
|
| 312 |
+
# Get the appropriate prompt
|
| 313 |
+
if stage == "stage_2":
|
| 314 |
+
prompt_key = "stage_2_transition"
|
| 315 |
+
elif stage == "stage_1":
|
| 316 |
+
prompt_key = "stage_1_commonsense"
|
| 317 |
+
else:
|
| 318 |
+
prompt_key = stage
|
| 319 |
+
|
| 320 |
+
prompt_template = TURABIAN_PROMPTS.get(prompt_key)
|
| 321 |
+
|
| 322 |
+
if not prompt_template:
|
| 323 |
+
return f"Error: Stage {stage} not found."
|
| 324 |
+
|
| 325 |
+
# Handle special case for warrant stage that needs both reason and claim
|
| 326 |
+
if stage == "stage_3d":
|
| 327 |
+
if not reason_text.strip() or not claim_text.strip():
|
| 328 |
+
return "For warrant analysis, please provide both a reason and a claim."
|
| 329 |
+
prompt = prompt_template.format(reason=reason_text, claim=claim_text)
|
| 330 |
+
else:
|
| 331 |
+
prompt = prompt_template.format(input=input_text)
|
| 332 |
+
|
| 333 |
+
try:
|
| 334 |
+
# Generate response using Llama 3.3
|
| 335 |
+
messages = [{"role": "user", "content": prompt}]
|
| 336 |
+
|
| 337 |
+
response = client.chat_completion(
|
| 338 |
+
messages=messages,
|
| 339 |
+
max_tokens=1500,
|
| 340 |
+
temperature=0.7,
|
| 341 |
+
top_p=0.9
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
return response.choices[0].message.content
|
| 345 |
+
|
| 346 |
+
except Exception as e:
|
| 347 |
+
return f"Error processing request: {str(e)}"
|
| 348 |
+
|
| 349 |
+
# Custom CSS for better styling
|
| 350 |
+
custom_css = """
|
| 351 |
+
.stage-container {
|
| 352 |
+
border: 2px solid #4CAF50;
|
| 353 |
+
border-radius: 10px;
|
| 354 |
+
padding: 20px;
|
| 355 |
+
margin: 10px 0;
|
| 356 |
+
background-color: #f9f9f9;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
.stage-title {
|
| 360 |
+
color: #2E7D32;
|
| 361 |
+
font-size: 1.2em;
|
| 362 |
+
font-weight: bold;
|
| 363 |
+
margin-bottom: 10px;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
.progress-indicator {
|
| 367 |
+
background-color: #E3F2FD;
|
| 368 |
+
padding: 10px;
|
| 369 |
+
border-radius: 5px;
|
| 370 |
+
margin-bottom: 15px;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
.output-box {
|
| 374 |
+
background-color: #FAFAFA;
|
| 375 |
+
border: 1px solid #E0E0E0;
|
| 376 |
+
border-radius: 5px;
|
| 377 |
+
padding: 15px;
|
| 378 |
+
font-family: monospace;
|
| 379 |
+
line-height: 1.6;
|
| 380 |
+
}
|
| 381 |
+
"""
|
| 382 |
+
|
| 383 |
+
# Main Gradio interface
|
| 384 |
+
with gr.Blocks(title="Turabian Research Argument Assistant", css=custom_css, theme=gr.themes.Soft()) as app:
|
| 385 |
+
gr.Markdown("""
|
| 386 |
+
# π Turabian Research Argument Assistant
|
| 387 |
+
### *Based on "A Manual for Writers of Research Papers, Theses, and Dissertations" by Kate L. Turabian*
|
| 388 |
+
|
| 389 |
+
Develop your research argument step-by-step using Turabian's proven methodology. This tool guides you through all 6 stages from commonsense argument to final revision.
|
| 390 |
+
""")
|
| 391 |
+
|
| 392 |
+
with gr.Row():
|
| 393 |
+
with gr.Column(scale=2):
|
| 394 |
+
gr.Markdown("## π― Select Your Stage")
|
| 395 |
+
|
| 396 |
+
stage = gr.Radio(
|
| 397 |
+
choices=[
|
| 398 |
+
("π Stage 1: Commonsense Argument", "stage_1"),
|
| 399 |
+
("π Stage 2: Research Transition", "stage_2"),
|
| 400 |
+
("ποΈ Stage 3A: Claim Development", "stage_3a"),
|
| 401 |
+
("π Stage 3B: Evidence Mapping", "stage_3b"),
|
| 402 |
+
("β Stage 3C: Objection Analysis", "stage_3c"),
|
| 403 |
+
("π Stage 3D: Warrant Identification", "stage_3d"),
|
| 404 |
+
("π Stage 4A: Storyboard Creation", "stage_4a"),
|
| 405 |
+
("π Stage 4B: Organization Planning", "stage_4b"),
|
| 406 |
+
("βοΈ Stage 4C: Introduction & Conclusion", "stage_4c"),
|
| 407 |
+
("π Stage 4D: Key Terms", "stage_4d"),
|
| 408 |
+
("π Stage 5: Drafting Guidance", "stage_5"),
|
| 409 |
+
("π Stage 6: Revision Checklist", "stage_6")
|
| 410 |
+
],
|
| 411 |
+
value="stage_1",
|
| 412 |
+
label="Choose Your Current Stage"
|
| 413 |
+
)
|
| 414 |
+
|
| 415 |
+
# Dynamic stage information
|
| 416 |
+
stage_info = gr.Markdown("**Stage 1: Commonsense Argument** - Create your foundational argument")
|
| 417 |
+
|
| 418 |
+
# Input section
|
| 419 |
+
gr.Markdown("## π Your Input")
|
| 420 |
+
input_text = gr.Textbox(
|
| 421 |
+
label="Main Input",
|
| 422 |
+
placeholder="Enter your topic, argument, or text for this stage...",
|
| 423 |
+
lines=8,
|
| 424 |
+
max_lines=15
|
| 425 |
+
)
|
| 426 |
+
|
| 427 |
+
# Special inputs for warrant stage
|
| 428 |
+
with gr.Row(visible=False) as warrant_inputs:
|
| 429 |
+
reason_text = gr.Textbox(
|
| 430 |
+
label="Reason",
|
| 431 |
+
placeholder="Enter the specific reason...",
|
| 432 |
+
lines=3
|
| 433 |
+
)
|
| 434 |
+
claim_text = gr.Textbox(
|
| 435 |
+
label="Claim",
|
| 436 |
+
placeholder="Enter the specific claim...",
|
| 437 |
+
lines=3
|
| 438 |
+
)
|
| 439 |
+
|
| 440 |
+
process_btn = gr.Button("π Process Stage", variant="primary", size="lg")
|
| 441 |
+
|
| 442 |
+
with gr.Column(scale=3):
|
| 443 |
+
gr.Markdown("## π Stage Output")
|
| 444 |
+
output = gr.Textbox(
|
| 445 |
+
label="Analysis Results",
|
| 446 |
+
lines=30,
|
| 447 |
+
max_lines=40,
|
| 448 |
+
show_copy_button=True,
|
| 449 |
+
elem_classes=["output-box"]
|
| 450 |
+
)
|
| 451 |
+
|
| 452 |
+
gr.Markdown("""
|
| 453 |
+
## π How to Use This Tool
|
| 454 |
+
|
| 455 |
+
1. **Start with Stage 1** - Input your basic topic/idea
|
| 456 |
+
2. **Progress sequentially** - Each stage builds on the previous
|
| 457 |
+
3. **Copy outputs** - Use results from one stage as input for the next
|
| 458 |
+
4. **Take your time** - Turabian's method requires careful development
|
| 459 |
+
|
| 460 |
+
## π‘ Tips
|
| 461 |
+
- Keep outputs from each stage for reference
|
| 462 |
+
- Don't skip stages - each builds essential elements
|
| 463 |
+
- Stage 3D (Warrants) requires both a reason and claim
|
| 464 |
+
- Use stage 4+ outputs to guide your actual writing
|
| 465 |
+
""")
|
| 466 |
+
|
| 467 |
+
# Update stage information when selection changes
|
| 468 |
+
def update_stage_info(stage_key):
|
| 469 |
+
info = get_stage_info(stage_key)
|
| 470 |
+
stage_desc = f"**{info['name']}** - {info['description']}"
|
| 471 |
+
|
| 472 |
+
# Show/hide warrant special inputs
|
| 473 |
+
if stage_key == "stage_3d":
|
| 474 |
+
return stage_desc, gr.update(visible=True)
|
| 475 |
+
else:
|
| 476 |
+
return stage_desc, gr.update(visible=False)
|
| 477 |
+
|
| 478 |
+
stage.change(
|
| 479 |
+
fn=update_stage_info,
|
| 480 |
+
inputs=[stage],
|
| 481 |
+
outputs=[stage_info, warrant_inputs]
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
# Process button click
|
| 485 |
+
process_btn.click(
|
| 486 |
+
fn=process_stage,
|
| 487 |
+
inputs=[stage, input_text, reason_text, claim_text],
|
| 488 |
+
outputs=output,
|
| 489 |
+
show_progress=True
|
| 490 |
+
)
|
| 491 |
+
|
| 492 |
+
if __name__ == "__main__":
|
| 493 |
+
app.launch()
|