Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Commit
•
1997c01
1
Parent(s):
7f06f2c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import json
|
5 |
+
from io import StringIO
|
6 |
+
|
7 |
+
def test(input_json):
|
8 |
+
print("Received input")
|
9 |
+
# Parse the input JSON string
|
10 |
+
try:
|
11 |
+
inputs = json.loads(input_json)
|
12 |
+
except json.JSONDecodeError:
|
13 |
+
inputs = json.loads(input_json.replace("'", '"'))
|
14 |
+
print("Parsed input keys:", inputs.keys())
|
15 |
+
|
16 |
+
multiplication = [-(inputs["alpha"]) * float(item) for item in inputs["a_list"]]
|
17 |
+
new_df = pd.DataFrame(index=inputs["dataframe"].index, columns=inputs["dataframe"].columns)
|
18 |
+
multiplier_series = pd.Series(inputs["a_list"], index=inputs["dataframe"].index)
|
19 |
+
new_df["new column"] = inputs["dataframe"].mul(multiplier_series, axis=0)
|
20 |
+
|
21 |
+
|
22 |
+
# Prepare the output
|
23 |
+
output = {
|
24 |
+
"test result": test
|
25 |
+
}
|
26 |
+
|
27 |
+
return json.dumps(output)
|
28 |
+
|
29 |
+
# Define the Gradio interface with a single JSON input
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=test,
|
32 |
+
inputs=gr.Textbox(label="Input JSON", lines=20, placeholder="Enter JSON with all parameters here..."),
|
33 |
+
outputs=gr.JSON(label="Output JSON"),
|
34 |
+
title="testspace"
|
35 |
+
)
|
36 |
+
|
37 |
+
iface.launch()
|