sanketmalde commited on
Commit
af06011
·
1 Parent(s): b815aed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -5
app.py CHANGED
@@ -1,11 +1,58 @@
 
 
1
  import gradio as gr
2
  import pandas as pd
3
 
4
- def readCSV(file):
5
- df = pd.read_csv(file)
6
- return "All good!"
 
7
 
8
- demo = gr.Interface(fn=readCSV, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  if __name__ == "__main__":
11
- demo.launch(show_api=False, debug=True)
 
1
+ import os
2
+ import json
3
  import gradio as gr
4
  import pandas as pd
5
 
6
+ def read_csv(csv_file):
7
+ df = pd.read_csv(csv_file)
8
+ json_output = convert_df_to_json(df, os.path.splitext(os.path.basename(csv_file))[0])
9
+ return generate_prompt(json_output)
10
 
11
+ def generate_prompt(json_output):
12
+ preamble = """
13
+ Given below is the data found in a relational database table in JSON format:
14
+
15
+ """
16
+
17
+ mid = """
18
+
19
+ For each column, tell me whether the data is of one of the following types: """
20
+
21
+ end = """
22
+
23
+ Your output should be in the following format:
24
+
25
+ { "tableName": "table_name",
26
+ "columns": [
27
+ {"columnName": "column1", "columnType": “one of the types given above”},
28
+ {"columnName": "column2", "columnType": “one of the types given above”},
29
+
30
+ ]
31
+ }
32
+
33
+ """
34
+
35
+ prompt = preamble + json.dumps(json_output) + mid + types_str + end
36
+ return prompt
37
+
38
+ def convert_df_to_json(df, table_name):
39
+ json_output = {
40
+ "tableName": table_name,
41
+ "columns": []
42
+ }
43
+
44
+ for column in df.columns:
45
+ column_info = {
46
+ "columnName": column,
47
+ "exampleValues": df[column].tolist()
48
+ }
49
+ json_output["columns"].append(column_info)
50
+
51
+ return json_output
52
+
53
+ known_types = ["NAME", "ADDRESS", "TELEPHONE NUMBER", "SOCIAL SECURITY NUMBER", "CREDIT CARD NUMBER" , "UNKNOWN"]
54
+ types_str = ', '.join(map(str, known_types))
55
+ demo = gr.Interface(fn=read_csv, inputs="text", outputs="text")
56
 
57
  if __name__ == "__main__":
58
+ demo.launch(show_api=False, debug=True)