File size: 1,485 Bytes
b966bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from meutils.pipe import *
from appzoo.streamlit_app import Page

import streamlit as st

import m2cgen as m2c


class MyPage(Page):

    def main(self):
        with st.form("Coding"):
            file = st.file_uploader('上传默模型文件')
            if file:
                estimator = joblib.load(file)
            else:
                estimator = joblib.load(get_resolve_path('../data/lr.pkl', __file__))

            languages = [
                'python',
                'java',
                'go',
                'c',
                'c_sharp',
                'r',
                'dart',
                'elixir',
                'f_sharp',
                'haskell',
                'javascript',
                'php',
                'powershell',
                'ruby',
                'rust',
                'visual_basic'
            ]

            _ = st.selectbox('选择输出语言', languages)

            if st.form_submit_button('开始转换'):
                code = m2c.__getattribute__(f'export_to_{_}')(estimator)

                st.markdown("##### code:")
                st.code(code)



if __name__ == '__main__':
    app_title = "ModelToCode"
    app_info = """
    将训练过的统计模型转化为本地代码(`Python, C, Java, Go, JavaScript, Visual Basic, c#, PowerShell, R, PHP, Dart, Haskell, Ruby, f#, Rust, Elixir`)。
    """
    MyPage(
        app_title=f"# {app_title}",
        app_info=f"> {app_info}",
    ).main()