mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
55f664f297
* changes * add changeset * changes * changes * changes * changes * changes * changes * changeas * changes * add changeset * changes * add changeset * changes * changes * changes * changes * changes * changes * changes * changes * add changeset * changes * cganges * changes * changes * changes * changes * add changeset * changes * chagnes * changes * changes * changes * changes * changes * js * remove console log * changes * changes * changes * changes * changes * changes * changes * changes * changes * add changeset * changes * chnages * changes * cnages * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * add changeset * changes * changes * changes * changes * changes * changes * changes * add changeset * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * add changeset * Add `state.change` listener (#8297) * state changes * changes --------- Co-authored-by: Ali Abid <aliabid94@gmail.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * changes * changes * add changeset * changes * changes * changes * changes * changes * changes --------- Co-authored-by: Ali Abid <aliabid94@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
import pytest
|
|
|
|
import gradio as gr
|
|
from gradio import utils
|
|
|
|
|
|
class TestPlot:
|
|
@pytest.mark.asyncio
|
|
async def test_in_interface_as_output(self):
|
|
"""
|
|
Interface, process
|
|
"""
|
|
|
|
def plot(num):
|
|
import matplotlib.pyplot as plt
|
|
|
|
fig = plt.figure()
|
|
plt.plot(range(num), range(num))
|
|
return fig
|
|
|
|
iface = gr.Interface(plot, "slider", "plot")
|
|
with utils.MatplotlibBackendMananger():
|
|
output = await iface.process_api(block_fn=0, inputs=[10], state={})
|
|
assert output["data"][0]["type"] == "matplotlib"
|
|
assert output["data"][0]["plot"].startswith("data:image/webp;base64")
|
|
|
|
def test_static(self):
|
|
"""
|
|
postprocess
|
|
"""
|
|
with utils.MatplotlibBackendMananger():
|
|
import matplotlib.pyplot as plt
|
|
|
|
fig = plt.figure()
|
|
plt.plot([1, 2, 3], [1, 2, 3])
|
|
|
|
component = gr.Plot(fig)
|
|
assert component.get_config().get("value") is not None
|
|
component = gr.Plot(None)
|
|
assert component.get_config().get("value") is None
|
|
|
|
def test_postprocess_altair(self):
|
|
import altair as alt
|
|
from vega_datasets import data
|
|
|
|
cars = data.cars()
|
|
chart = (
|
|
alt.Chart(cars)
|
|
.mark_point()
|
|
.encode(
|
|
x="Horsepower",
|
|
y="Miles_per_Gallon",
|
|
color="Origin",
|
|
)
|
|
)
|
|
out = gr.Plot().postprocess(chart).model_dump()
|
|
assert isinstance(out["plot"], str)
|
|
assert out["plot"] == chart.to_json()
|
|
|
|
def test_plot_format_parameter(self):
|
|
"""
|
|
postprocess
|
|
"""
|
|
with utils.MatplotlibBackendMananger():
|
|
import matplotlib.pyplot as plt
|
|
|
|
fig = plt.figure()
|
|
plt.plot([1, 2, 3], [1, 2, 3])
|
|
|
|
component = gr.Plot(format="jpeg")
|
|
assert component.postprocess(fig).plot.startswith("data:image/jpeg")
|