-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpt4_api.py
89 lines (67 loc) · 2.31 KB
/
gpt4_api.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#encoding:utf8
import requests
import json
import pandas as pd
from tqdm import tqdm
import uuid
import csv
def GPT4(q):
try:
if not q:
pass
token = ""
url = f"http://43.153.59.172:30002/openai"
para = {
"question": q,
"token":token
}
answer = requests.post(url=url, json=para).text
return answer
except Exception as e:
if "Internal Server err" in e:
pass
def GPT35(q):
try:
if not q:
pass
token = ""
url = f"http://43.153.59.172:30001/openai"
para = {
"question": q,
"token":token
}
answer = requests.post(url=url, json=para).text
return answer
except Exception as e:
if "Internal Server err" in e:
pass
if __name__ == '__main__':
# 读取CSV文件
df = pd.read_csv("/mnt/data/music_audioset/Music_genre/genre_eval_segments_match.csv")
data = []
# 遍历DataFrame的每一行
for index, row in df.iterrows():
# 获取当前行的数据
YTID = row['YTID']
positive_labels = row['positive_labels']
# 将当前行数据转换为字典,并添加到data列表中
data_dict = {"YTID": YTID, "positive_labels": positive_labels}
data.append(data_dict)
with open("music_audioset_genre_eval_gpt4.txt", "w") as f:
for item in tqdm(data):
YTID = item["YTID"]
label = item["positive_labels"]
label_list = label.split("\t")
text = '''
I will give you a list containing sound events. Write an one-sentence audio caption to describe these sounds.
Make sure you are using grammatical subject-verb-object sentences. Directly describe the sounds and avoid using the word “heard”. The caption should be less than 20 words.
The list is:{caption}
The format of each output sentence is as follows:
Caption:"",Chinese Translation:"".
'''.format(
caption=label_list
)
caption = GPT4(text)
print(caption)
f.write(f"{YTID}\t{caption}\n")
f.flush()