Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,48 +2,48 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 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 |
-
except Exception as e:
|
| 29 |
-
return None, f"Error: {str(e)}"
|
| 30 |
-
|
| 31 |
-
# --- Gradio Interface ---
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
-
gr.Markdown("##
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
)
|
| 41 |
|
| 42 |
-
run_btn = gr.Button("
|
| 43 |
|
| 44 |
-
df_output = gr.Dataframe(label="
|
| 45 |
file_output = gr.File(label="Download CSV")
|
| 46 |
|
| 47 |
-
run_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
demo.launch()
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
|
| 5 |
+
def process_inputs(user_input_json, session_id_json, project_id_json, chat_url, update_vars_json, output_vars_json):
|
| 6 |
+
# Convert JSON strings into Python lists
|
| 7 |
+
user_input = json.loads(user_input_json)
|
| 8 |
+
session_id = json.loads(session_id_json)
|
| 9 |
+
project_id = json.loads(project_id_json)
|
| 10 |
+
update_vars = json.loads(update_vars_json)
|
| 11 |
+
output_vars = json.loads(output_vars_json)
|
| 12 |
+
|
| 13 |
+
# --- Your function logic here ---
|
| 14 |
+
df = pd.DataFrame({
|
| 15 |
+
"user_input": user_input,
|
| 16 |
+
"session_id": session_id,
|
| 17 |
+
"project_id": project_id,
|
| 18 |
+
"chat_url": [chat_url] * len(user_input),
|
| 19 |
+
"update_variables": update_vars,
|
| 20 |
+
"output_variables": output_vars
|
| 21 |
+
})
|
| 22 |
+
|
| 23 |
+
csv_path = "output.csv"
|
| 24 |
+
df.to_csv(csv_path, index=False)
|
| 25 |
+
return df, csv_path
|
| 26 |
+
|
| 27 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown("## π¬ JSON Input β DataFrame β CSV Export")
|
| 30 |
+
|
| 31 |
+
user_input = gr.Code(label="user_input (list[str] or list[list[str]])", language="json", value='["Hello", ["Hi", "How are you?"]]')
|
| 32 |
+
session_id = gr.Code(label="session_id (list[str])", language="json", value='["s1", "s2"]')
|
| 33 |
+
project_id = gr.Code(label="project_id (list[str])", language="json", value='["p1", "p2"]')
|
| 34 |
+
chat_url = gr.Textbox(label="chat_url", value="https://example.com/chat")
|
| 35 |
+
update_vars = gr.Code(label="update_variables (list[str])", language="json", value='["update1", "update2"]')
|
| 36 |
+
output_vars = gr.Code(label="output_variables (list[str])", language="json", value='["out1", "out2"]')
|
| 37 |
|
| 38 |
+
run_btn = gr.Button("Run Function")
|
| 39 |
|
| 40 |
+
df_output = gr.Dataframe(label="Output DataFrame", interactive=False)
|
| 41 |
file_output = gr.File(label="Download CSV")
|
| 42 |
|
| 43 |
+
run_btn.click(
|
| 44 |
+
fn=process_inputs,
|
| 45 |
+
inputs=[user_input, session_id, project_id, chat_url, update_vars, output_vars],
|
| 46 |
+
outputs=[df_output, file_output]
|
| 47 |
+
)
|
| 48 |
|
| 49 |
demo.launch()
|