uartimcs commited on
Commit
c65837d
·
verified ·
1 Parent(s): 8d02019

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import json
3
+ import gradio as gr
4
+
5
+ def create_jsonl(csv_file):
6
+ df = pd.read_csv(csv_file)
7
+
8
+ column_list = df.columns
9
+ output = 'metadata.jsonl'
10
+
11
+ total_data = []
12
+
13
+ for index, row in df.iterrows():
14
+
15
+ data = {}
16
+
17
+ for column in column_list:
18
+
19
+ if column == 'file_name':
20
+ file_name = row[column]
21
+
22
+ data[column] = row[column]
23
+
24
+ row_data = {"file_name": file_name, "ground_truth": json.dumps(data)}
25
+
26
+ total_data.append(row_data)
27
+
28
+ with open(output, 'a', encoding='utf-8') as f:
29
+
30
+ for row_data in total_data:
31
+ f.write(json.dumps(row_data) + '\n')
32
+
33
+ return output
34
+
35
+ demo = gr.Interface(fn=create_jsonl,inputs="csv",outputs="text", title=f"jsonl converter",)
36
+ demo.launch()
37
+
38
+
39
+
40
+
41
+
42
+