import gradio as gr
def beautify_diagram_types(diagram_types):
first_diagram = "use-case-diagram"
if first_diagram in diagram_types:
diagram_types.remove(first_diagram)
diagram_types.insert(0, first_diagram)
diagram_types.sort()
return [name.replace("-", " ").title() for name in diagram_types]
def create_interface(diagram_types, respond):
diagram_types = beautify_diagram_types(diagram_types)
with gr.Blocks(title="PlantUML Agent", theme=gr.themes.Soft()) as demo:
gr.HTML(
"""
PlantUML Agent
Generate UML diagrams using PlantUML syntax with the help of an AI agent.
"""
)
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("## π Mistral API Key Input")
api_key_input = gr.Textbox(
label="π Mistral API Key",
placeholder="Input your Mistral API key here",
type="password",
lines=1,
interactive=True
)
gr.Markdown("## π Diagram Type")
diagram_dropdown = gr.Dropdown(
choices=diagram_types,
value="Use Case Diagram",
label="Choose the type of UML diagram",
interactive=True
)
gr.Markdown("## π Input Description")
msg = gr.Textbox(
label="Describe your UML diagram",
placeholder="e.g., create a basic use case class",
value="Create a basic use case diagram",
lines=3,
interactive=True
)
gr.Markdown("## πΌοΈ Image (optional)")
image_input = gr.Image(
label="Upload an image to assist in diagram generation",
type="filepath",
interactive=True,
height=200,
)
submit = gr.Button("π Generate Diagram", variant="primary", size="lg")
with gr.Column(scale=2):
gr.Markdown("## π Generated Diagram")
gr.Markdown("### PlantUML Code")
diagram_text_output = gr.Code(
label="The generated PlantUML code",
lines=15,
interactive=False,
)
gr.Markdown("### Diagram Preview")
diagram_output = gr.HTML(
label="Visual representation of your diagram",
elem_id="diagram-preview"
)
gr.HTML(
"""
Powered by Mistral, BM25Retriever, LangChain, Docling, LRUCache, Gradio, and PlantUML.
"""
)
submit.click(respond, [msg, diagram_dropdown, image_input, api_key_input], [msg, diagram_text_output, diagram_output])
msg.submit(respond, [msg, diagram_dropdown, image_input, api_key_input], [msg, diagram_text_output, diagram_output])
return demo