Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
import uuid
|
|
|
|
| 5 |
|
| 6 |
def convert_inputs(user_input, var):
|
| 7 |
if var == "__random__":
|
|
@@ -39,11 +40,60 @@ def process_inputs(user_input_json, session_id_json, project_id, chat_url, updat
|
|
| 39 |
"update_variables": update_vars,
|
| 40 |
"output_variables": output_vars,
|
| 41 |
"answer": [[] * len(x) if isinstance(x, list) else [] for x in user_input]
|
| 42 |
-
})
|
| 43 |
|
| 44 |
return df
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
def run_process(df):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
csv_path = "output.csv"
|
| 48 |
df.to_csv(csv_path, index=False)
|
| 49 |
return csv_path
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
import uuid
|
| 5 |
+
import requests
|
| 6 |
|
| 7 |
def convert_inputs(user_input, var):
|
| 8 |
if var == "__random__":
|
|
|
|
| 40 |
"update_variables": update_vars,
|
| 41 |
"output_variables": output_vars,
|
| 42 |
"answer": [[] * len(x) if isinstance(x, list) else [] for x in user_input]
|
| 43 |
+
})
|
| 44 |
|
| 45 |
return df
|
| 46 |
|
| 47 |
+
|
| 48 |
+
def run_chat(chat_url, project_id, session_id, user_input, update_variables, output_variables, token):
|
| 49 |
+
req = requests.post(
|
| 50 |
+
chat_url,
|
| 51 |
+
json={
|
| 52 |
+
"project_id": project_id,
|
| 53 |
+
"session_id": session_id,
|
| 54 |
+
"user_input": user_input,
|
| 55 |
+
"update_variables": update_variables,
|
| 56 |
+
"output_variables": output_variables
|
| 57 |
+
},
|
| 58 |
+
headers={"Authorization" : f"Bearer {token}"}
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
print("[REQ CONTENT]", req.content)
|
| 62 |
+
|
| 63 |
+
out = req.json()["data"]["results"]
|
| 64 |
+
|
| 65 |
+
print("[OUT]",out)
|
| 66 |
+
|
| 67 |
+
return out.encode('utf-8').decode('unicode_escape')
|
| 68 |
+
|
| 69 |
+
|
| 70 |
def run_process(df):
|
| 71 |
+
for index, row in df.iterrows():
|
| 72 |
+
if isinstance(row["user_input"], list):
|
| 73 |
+
answer = []
|
| 74 |
+
for user_input in row["user_input"]:
|
| 75 |
+
answer.append(
|
| 76 |
+
run_chat(
|
| 77 |
+
row["chat_url"],
|
| 78 |
+
row["project_id"],#: project_id,
|
| 79 |
+
row["session_id"],#: session_id,
|
| 80 |
+
user_input,#: user_input,
|
| 81 |
+
row["update_variables"],#: update_variables,
|
| 82 |
+
row["output_variables"],
|
| 83 |
+
row["token"]
|
| 84 |
+
)
|
| 85 |
+
)
|
| 86 |
+
else:
|
| 87 |
+
answer = run_chat(
|
| 88 |
+
row["chat_url"],
|
| 89 |
+
row["project_id"],#: project_id,
|
| 90 |
+
row["session_id"],#: session_id,
|
| 91 |
+
row["user_input"],#: user_input,
|
| 92 |
+
row["update_variables"],#: update_variables,
|
| 93 |
+
row["output_variables"],
|
| 94 |
+
row["token"]
|
| 95 |
+
)
|
| 96 |
+
df.loc[index, "answer"] = answer
|
| 97 |
csv_path = "output.csv"
|
| 98 |
df.to_csv(csv_path, index=False)
|
| 99 |
return csv_path
|