-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed_db.py
More file actions
32 lines (27 loc) · 1.05 KB
/
seed_db.py
File metadata and controls
32 lines (27 loc) · 1.05 KB
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
import json
import requests
# The URL
URL = "http://127.0.0.1:8000/pairs"
def seed_database():
try:
with open("translation_pairs.jsonl", "r") as f:
for line in f:
# Parse each line of the JSONL file
data = json.loads(line)
# Format
payload = {
"source_language": data["source_language"],
"target_language": data["target_language"],
"sentence": data["sentence"],
"translation": data["translation"]
}
# -> API
response = requests.post(URL, json=payload)
if response.status_code == 200:
print(f"Added: {data['sentence'][:30]}...")
else:
print(f"Failed to add: {data['sentence'][:30]}")
except FileNotFoundError:
print("Error: translation_pairs.jsonl not found. Make sure it's in this folder.")
if __name__ == "__main__":
seed_database()