Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import graphviz | |
| import tempfile | |
| import os | |
| def text_to_chart(text): | |
| # Create diagram logic (replace this with NLP if needed) | |
| dot = graphviz.Digraph(format='png') | |
| dot.attr(rankdir="LR", size="20,10") # Increase chart canvas size | |
| dot.attr(dpi="300") # High-resolution output | |
| # Naive split into phrases by period | |
| steps = [s.strip() for s in text.split('.') if s.strip()] | |
| previous = None | |
| for i, step in enumerate(steps): | |
| node_name = f"step{i}" | |
| dot.node(node_name, step) | |
| if previous: | |
| dot.edge(previous, node_name) | |
| previous = node_name | |
| # Save image to temp file | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp: | |
| tmp.write(dot.pipe()) | |
| tmp_path = tmp.name | |
| return tmp_path | |
| def generate_chart(text): | |
| image_path = text_to_chart(text) | |
| return image_path, image_path | |
| with gr.Blocks(title="🧠 Text to Explanation Chart Generator") as demo: | |
| gr.Markdown("## 🧠 Text to Explanation Chart Generator\nEnter a paragraph and click 'Convert to Chart' to see a visual explanation. You can download the image.") | |
| with gr.Row(): | |
| text_input = gr.Textbox(label="📝 Enter Your Text", lines=8, placeholder="Write something like how a system or process works...") | |
| with gr.Row(): | |
| convert_btn = gr.Button("📊 Convert to Chart") | |
| with gr.Row(): | |
| chart_image = gr.Image(label="🖼️ Generated Chart", type="filepath") | |
| download_file = gr.File(label="⬇️ Download Chart (PNG)") | |
| convert_btn.click(fn=generate_chart, inputs=text_input, outputs=[chart_image, download_file]) | |
| demo.launch() |