qunfei commited on
Commit
815cfd4
·
1 Parent(s): bed9222

git add simple application

Browse files
Files changed (1) hide show
  1. app.py +65 -2
app.py CHANGED
@@ -1,4 +1,67 @@
 
1
  import streamlit as st
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from io import StringIO
2
  import streamlit as st
3
 
4
+
5
+ class CoreClient:
6
+
7
+ def generate(self, source: str, target: str, code: str):
8
+ return source
9
+
10
+
11
+ st.set_page_config(
12
+ page_title='A SQL Generative Pre-trained Transformer',
13
+ layout='wide',
14
+ initial_sidebar_state='expanded'
15
+ )
16
+
17
+ databases = ['Oracle', 'SQLServer', 'MySQL', 'DB2', 'PostgreSQL', 'Snowflake', 'Redshift']
18
+ # -------------
19
+
20
+ st.sidebar.header('A SQL Transformer')
21
+
22
+ source_database = st.sidebar.selectbox(
23
+ label='Source Database',
24
+ options=databases,
25
+ index=0
26
+ )
27
+
28
+ target_database = st.sidebar.selectbox(
29
+ label='Target Database',
30
+ options=databases,
31
+ index=4
32
+ )
33
+
34
+ input_text = st.sidebar.text_area(
35
+ label='Insert SQL',
36
+ placeholder='select * from now()'
37
+ )
38
+
39
+ input_file = st.sidebar.file_uploader(
40
+ label="Choose a SQL file",
41
+ accept_multiple_files=False)
42
+
43
+ client = CoreClient()
44
+
45
+
46
+ def transform():
47
+ code = input_text
48
+ source = source_database
49
+ target = target_database
50
+ if code:
51
+ ts = client.generate(source, target, code)
52
+ for solution in ts:
53
+ st.code(solution, language='sql')
54
+ else:
55
+ if input_file is not None:
56
+ # To convert to a string based IO:
57
+ stringio = StringIO(input_file.getvalue().decode("utf-8"))
58
+ # To read file as string:
59
+ sql = stringio.read()
60
+ ts = client.generate(source, target, sql)
61
+ for solution in ts:
62
+ st.code(solution, language='sql')
63
+
64
+
65
+ # ---------------------------------------
66
+
67
+ transform()