|
import gradio as gr |
|
import matplotlib.pyplot as plt |
|
import io |
|
import base64 |
|
|
|
|
|
a = 35 |
|
b = 40 |
|
c = 25 |
|
|
|
|
|
def create_bar_chart(a, b, c): |
|
|
|
labels = ['A', 'B', 'C'] |
|
values = [a, b, c] |
|
|
|
fig, ax = plt.subplots() |
|
ax.bar(labels, values, color=['#ff9999','#66b3ff','#99ff99']) |
|
|
|
|
|
ax.set_ylabel('Valores') |
|
ax.set_title('Gráfico de Barras') |
|
|
|
|
|
buf = io.BytesIO() |
|
plt.savefig(buf, format='png') |
|
buf.seek(0) |
|
img_base64 = base64.b64encode(buf.read()).decode('utf-8') |
|
buf.close() |
|
|
|
return img_base64 |
|
|
|
|
|
def gradio_interface(a, b, c): |
|
img_base64 = create_bar_chart(a, b, c) |
|
return img_base64 |
|
|
|
|
|
demo = gr.Interface( |
|
fn=gradio_interface, |
|
inputs=[ |
|
gr.Number(value=a, label="Valor A"), |
|
gr.Number(value=b, label="Valor B"), |
|
gr.Number(value=c, label="Valor C") |
|
], |
|
outputs=gr.Image(label="Gráfico de Barras"), |
|
title="Generador de Gráficos de Barras", |
|
description="Genera un gráfico de barras basado en los valores de A, B y C" |
|
) |
|
|
|
demo.launch(share=True) |
|
|