Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- app.py +136 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
def simulate_processing(content: str, operation: str, iteration: int) -> tuple[str, int, str]:
|
| 6 |
+
"""
|
| 7 |
+
Simulates a Review, Revise, Refactor, and Iterate workflow.
|
| 8 |
+
In a real app, this would connect to an LLM or AST analyzer.
|
| 9 |
+
"""
|
| 10 |
+
if not content.strip():
|
| 11 |
+
return "", 0, "⚠️ Please enter some text or code to begin."
|
| 12 |
+
|
| 13 |
+
# Simulate processing time
|
| 14 |
+
time.sleep(0.5)
|
| 15 |
+
|
| 16 |
+
result = content
|
| 17 |
+
status_msg = ""
|
| 18 |
+
|
| 19 |
+
if operation == "Review":
|
| 20 |
+
status_msg = "✅ Review Complete: Syntax looks valid. Suggest improvements for readability."
|
| 21 |
+
result = f"# REVIEW LOG {time.ctime()}\n# Status: Pass\n# Note: Consider adding docstrings.\n\n{content}"
|
| 22 |
+
|
| 23 |
+
elif operation == "Revise":
|
| 24 |
+
status_msg = "✍️ Revision Complete: Updated phrasing and tone."
|
| 25 |
+
# Simple text simulation: capitalize first letter of sentences
|
| 26 |
+
sentences = content.split('. ')
|
| 27 |
+
revised = '. '.join([s.strip().capitalize() for s in sentences])
|
| 28 |
+
result = revised if revised else content
|
| 29 |
+
|
| 30 |
+
elif operation == "Refactor":
|
| 31 |
+
status_msg = "⚙️ Refactoring Complete: Optimized structure."
|
| 32 |
+
# Simple code simulation
|
| 33 |
+
result = content.replace("var ", "let ").replace(" ", " ")
|
| 34 |
+
result = f"# REFACTORED VERSION\n{result}"
|
| 35 |
+
|
| 36 |
+
elif operation == "Iterate":
|
| 37 |
+
iteration += 1
|
| 38 |
+
status_msg = f"🚀 Iteration {iteration} generated."
|
| 39 |
+
result = f"# --- ITERATION {iteration} ---\n# Updated based on previous feedback\n{content}"
|
| 40 |
+
|
| 41 |
+
return result, iteration, status_msg
|
| 42 |
+
|
| 43 |
+
# Gradio 6 Application
|
| 44 |
+
# Note: gr.Blocks() takes NO parameters in Gradio 6
|
| 45 |
+
with gr.Blocks() as demo:
|
| 46 |
+
|
| 47 |
+
# Header with required link
|
| 48 |
+
gr.HTML("""
|
| 49 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
| 50 |
+
<h1>🔄 Code & Text Workflow Studio</h1>
|
| 51 |
+
<p style="color: #666;">Review, Revise, Refactor, and Iterate your content in one place.</p>
|
| 52 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="text-decoration: none; color: #f97316; font-weight: bold;">
|
| 53 |
+
Built with anycoder
|
| 54 |
+
</a>
|
| 55 |
+
</div>
|
| 56 |
+
""")
|
| 57 |
+
|
| 58 |
+
with gr.Sidebar(position="left"):
|
| 59 |
+
gr.Markdown("### 🛠️ Workflow Controls")
|
| 60 |
+
|
| 61 |
+
operation_mode = gr.Radio(
|
| 62 |
+
choices=["Review", "Revise", "Refactor", "Iterate"],
|
| 63 |
+
value="Review",
|
| 64 |
+
label="Select Operation",
|
| 65 |
+
info="Choose the action to perform on the input."
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
iteration_state = gr.Number(value=0, label="Iteration Count", interactive=False)
|
| 69 |
+
|
| 70 |
+
gr.Markdown("---")
|
| 71 |
+
gr.Markdown("### ℹ️ Guide")
|
| 72 |
+
gr.Markdown("""
|
| 73 |
+
1. **Review**: Analyze syntax and structure.
|
| 74 |
+
2. **Revise**: Improve phrasing and tone.
|
| 75 |
+
3. **Refactor**: Optimize code structure.
|
| 76 |
+
4. **Iterate**: Create a new version copy.
|
| 77 |
+
""")
|
| 78 |
+
|
| 79 |
+
with gr.Row():
|
| 80 |
+
with gr.Column(scale=1):
|
| 81 |
+
input_code = gr.Code(
|
| 82 |
+
label="Input Content",
|
| 83 |
+
language="python",
|
| 84 |
+
placeholder="Paste your code or text here...",
|
| 85 |
+
lines=15
|
| 86 |
+
)
|
| 87 |
+
with gr.Row():
|
| 88 |
+
clear_btn = gr.Button("Clear", variant="secondary", scale=1)
|
| 89 |
+
run_btn = gr.Button("Run Process", variant="primary", scale=2)
|
| 90 |
+
|
| 91 |
+
with gr.Column(scale=1):
|
| 92 |
+
status_output = gr.Textbox(label="System Status", interactive=False)
|
| 93 |
+
output_code = gr.Code(
|
| 94 |
+
label="Processed Output",
|
| 95 |
+
language="python",
|
| 96 |
+
lines=15,
|
| 97 |
+
interactive=True
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# Event Listeners
|
| 101 |
+
# Gradio 6 uses api_visibility instead of api_name for visibility control
|
| 102 |
+
run_btn.click(
|
| 103 |
+
fn=simulate_processing,
|
| 104 |
+
inputs=[input_code, operation_mode, iteration_state],
|
| 105 |
+
outputs=[output_code, iteration_state, status_output],
|
| 106 |
+
api_visibility="public"
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
clear_btn.click(
|
| 110 |
+
fn=lambda: ["", 0, "", "Review"],
|
| 111 |
+
inputs=None,
|
| 112 |
+
outputs=[input_code, iteration_state, output_code, operation_mode],
|
| 113 |
+
api_visibility="private"
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
# Gradio 6 Launch Configuration
|
| 117 |
+
# ALL app-level parameters (theme, css, etc.) go here, NOT in gr.Blocks()
|
| 118 |
+
demo.launch(
|
| 119 |
+
theme=gr.themes.Soft(
|
| 120 |
+
primary_hue="indigo",
|
| 121 |
+
secondary_hue="blue",
|
| 122 |
+
neutral_hue="slate",
|
| 123 |
+
font=gr.themes.GoogleFont("Inter"),
|
| 124 |
+
text_size="md",
|
| 125 |
+
spacing_size="md",
|
| 126 |
+
radius_size="lg"
|
| 127 |
+
).set(
|
| 128 |
+
button_primary_background_fill="*primary_500",
|
| 129 |
+
button_primary_background_fill_hover="*primary_600",
|
| 130 |
+
block_background_fill="*background_fill_secondary",
|
| 131 |
+
),
|
| 132 |
+
footer_links=[
|
| 133 |
+
{"label": "View Source", "url": "https://github.com/gradio-app/gradio"},
|
| 134 |
+
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
|
| 135 |
+
]
|
| 136 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio
|