Spaces:
Runtime error
Runtime error
File size: 2,199 Bytes
bf5e43e |
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 |
import gradio as gr
import matplotlib.pyplot as plt
import numpy as np
import io
from PIL import Image
import graphviz
def generate_graph(code):
# Example: Assuming code is a multiplier for a simple function
try:
multiplier = float(code)
except ValueError:
multiplier = 1
x = np.linspace(0, 10, 100)
y = np.sin(x) * multiplier
plt.figure()
plt.plot(x, y)
plt.title("Generated Graph")
buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
img = Image.open(buf)
return img
def generate_diagram(code):
# Example: Use code as label text in the diagram
dot = graphviz.Digraph(comment='Diagram')
dot.node('A', 'Start')
dot.node('B', code)
dot.edge('A', 'B')
buf = io.BytesIO(dot.pipe(format='png'))
buf.seek(0)
img = Image.open(buf)
return img
def generate_mindmap(code):
# Example: Use code as label text in the mind map
dot = graphviz.Digraph(comment='Mind Map', graph_attr={'rankdir': 'LR'})
dot.node('Root', 'Root')
dot.node('Child1', code)
dot.edge('Root', 'Child1')
buf = io.BytesIO(dot.pipe(format='png'))
buf.seek(0)
img = Image.open(buf)
return img
def main(graph_code, diagram_code, mindmap_code):
graph_img = generate_graph(graph_code)
diagram_img = generate_diagram(diagram_code)
mindmap_img = generate_mindmap(mindmap_code)
return graph_img, diagram_img, mindmap_img
interface = gr.Interface(
fn=main,
inputs=[
gr.inputs.Textbox(lines=2, placeholder="Paste code or text for graph", label="Graph Code"),
gr.inputs.Textbox(lines=2, placeholder="Paste code or text for diagram", label="Diagram Code"),
gr.inputs.Textbox(lines=2, placeholder="Paste code or text for mind map", label="Mind Map Code")
],
outputs=[
gr.outputs.Image(type="pil", label="Generated Graph"),
gr.outputs.Image(type="pil", label="Generated Diagram"),
gr.outputs.Image(type="pil", label="Generated Mind Map")
],
title="Advanced Visual Generator",
description="Paste code or text to generate graphs, diagrams, and mind maps."
)
if __name__ == "__main__":
interface.launch() |