Spaces:
Runtime error
Runtime error
Upload fetch_data.py
Browse files- fetch_data.py +27 -0
fetch_data.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
def fetch_and_update_training_data(train_file):
|
5 |
+
model_name = "TitanQL"
|
6 |
+
export_type = "sentence"
|
7 |
+
request_url = f"http://20.247.235.135/AiBot/BE/api/PromptEnhancer/ExportPEList?modelName={model_name}&exportType={export_type}"
|
8 |
+
|
9 |
+
response = requests.get(request_url)
|
10 |
+
|
11 |
+
if response.status_code == 200:
|
12 |
+
try:
|
13 |
+
# Save response as CSV
|
14 |
+
with open(train_file + ".csv", "w", encoding="utf-8") as file:
|
15 |
+
file.write(response.text)
|
16 |
+
|
17 |
+
print("Training file updated successfully.")
|
18 |
+
|
19 |
+
# Read the updated CSV into a DataFrame
|
20 |
+
return pd.read_csv(train_file + ".csv")
|
21 |
+
|
22 |
+
except Exception as e:
|
23 |
+
print(f"Error processing the response: {e}")
|
24 |
+
return None
|
25 |
+
else:
|
26 |
+
print(f"Error fetching data: {response.status_code}")
|
27 |
+
return None
|