File size: 1,106 Bytes
1997c01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()