Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
import numpy as np | |
import json | |
from io import StringIO | |
def test(input_json): | |
print("Received input") | |
# Parse the input JSON string | |
try: | |
inputs = json.loads(input_json) | |
except json.JSONDecodeError: | |
inputs = json.loads(input_json.replace("'", '"')) | |
print("Parsed input keys:", inputs.keys()) | |
multiplication = [-(inputs["alpha"]) * float(item) for item in inputs["a_list"]] | |
new_df = pd.DataFrame(index=inputs["dataframe"].index, columns=inputs["dataframe"].columns) | |
multiplier_series = pd.Series(inputs["a_list"], index=inputs["dataframe"].index) | |
new_df["new column"] = inputs["dataframe"].mul(multiplier_series, axis=0) | |
# Prepare the output | |
output = { | |
"test result": test | |
} | |
return json.dumps(output) | |
# Define the Gradio interface with a single JSON input | |
iface = gr.Interface( | |
fn=test, | |
inputs=gr.Textbox(label="Input JSON", lines=20, placeholder="Enter JSON with all parameters here..."), | |
outputs=gr.JSON(label="Output JSON"), | |
title="testspace" | |
) | |
iface.launch() |