Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	交互优化
Browse files- config.py +1 -3
- functional_crazy.py +2 -2
- main.py +4 -4
- toolbox.py +23 -12
    	
        config.py
    CHANGED
    
    | @@ -16,15 +16,13 @@ if USE_PROXY: | |
| 16 | 
             
                    "http":  "socks5h://localhost:11284", 
         | 
| 17 | 
             
                    "https": "socks5h://localhost:11284", 
         | 
| 18 | 
             
                }
         | 
| 19 | 
            -
                print('网络代理状态:运行。')
         | 
| 20 | 
             
            else:
         | 
| 21 | 
             
                proxies = None
         | 
| 22 | 
            -
                print('网络代理状态:未配置。无代理状态下很可能无法访问。')
         | 
| 23 |  | 
| 24 |  | 
| 25 | 
             
            # [step 3]>> 以下配置可以优化体验,但大部分场合下并不需要修改
         | 
| 26 | 
             
            # 对话窗的高度
         | 
| 27 | 
            -
            CHATBOT_HEIGHT =  | 
| 28 |  | 
| 29 | 
             
            # 发送请求到OpenAI后,等待多久判定为超时
         | 
| 30 | 
             
            TIMEOUT_SECONDS = 25
         | 
|  | |
| 16 | 
             
                    "http":  "socks5h://localhost:11284", 
         | 
| 17 | 
             
                    "https": "socks5h://localhost:11284", 
         | 
| 18 | 
             
                }
         | 
|  | |
| 19 | 
             
            else:
         | 
| 20 | 
             
                proxies = None
         | 
|  | |
| 21 |  | 
| 22 |  | 
| 23 | 
             
            # [step 3]>> 以下配置可以优化体验,但大部分场合下并不需要修改
         | 
| 24 | 
             
            # 对话窗的高度
         | 
| 25 | 
            +
            CHATBOT_HEIGHT = 1116
         | 
| 26 |  | 
| 27 | 
             
            # 发送请求到OpenAI后,等待多久判定为超时
         | 
| 28 | 
             
            TIMEOUT_SECONDS = 25
         | 
    	
        functional_crazy.py
    CHANGED
    
    | @@ -18,7 +18,7 @@ def get_crazy_functionals(): | |
| 18 | 
             
                from crazy_functions.代码重写为全英文_多线程 import 全项目切换英文
         | 
| 19 |  | 
| 20 | 
             
                function_plugins = {
         | 
| 21 | 
            -
                    " | 
| 22 | 
             
                        "AsButton": False,  # 加入下拉菜单中
         | 
| 23 | 
             
                        "Function": 解析项目本身
         | 
| 24 | 
             
                    },
         | 
| @@ -30,7 +30,7 @@ def get_crazy_functionals(): | |
| 30 | 
             
                        "Color": "stop",    # 按钮颜色
         | 
| 31 | 
             
                        "Function": 解析一个C项目的头文件
         | 
| 32 | 
             
                    },
         | 
| 33 | 
            -
                    "解析整个C | 
| 34 | 
             
                        "Color": "stop",    # 按钮颜色
         | 
| 35 | 
             
                        "AsButton": False,  # 加入下拉菜单中
         | 
| 36 | 
             
                        "Function": 解析一个C项目
         | 
|  | |
| 18 | 
             
                from crazy_functions.代码重写为全英文_多线程 import 全项目切换英文
         | 
| 19 |  | 
| 20 | 
             
                function_plugins = {
         | 
| 21 | 
            +
                    "请解析并解构此项目本身(源码自译解)": {
         | 
| 22 | 
             
                        "AsButton": False,  # 加入下拉菜单中
         | 
| 23 | 
             
                        "Function": 解析项目本身
         | 
| 24 | 
             
                    },
         | 
|  | |
| 30 | 
             
                        "Color": "stop",    # 按钮颜色
         | 
| 31 | 
             
                        "Function": 解析一个C项目的头文件
         | 
| 32 | 
             
                    },
         | 
| 33 | 
            +
                    "解析整个C++项目(.cpp/.h)": {
         | 
| 34 | 
             
                        "Color": "stop",    # 按钮颜色
         | 
| 35 | 
             
                        "AsButton": False,  # 加入下拉菜单中
         | 
| 36 | 
             
                        "Function": 解析一个C项目
         | 
    	
        main.py
    CHANGED
    
    | @@ -54,7 +54,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as de | |
| 54 | 
             
                            stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
         | 
| 55 | 
             
                        with gr.Row():
         | 
| 56 | 
             
                            from check_proxy import check_proxy
         | 
| 57 | 
            -
                             | 
| 58 | 
             
                        with gr.Accordion("基础功能区", open=True) as area_basic_fn:
         | 
| 59 | 
             
                            with gr.Row():
         | 
| 60 | 
             
                                for k in functional:
         | 
| @@ -93,8 +93,8 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as de | |
| 93 | 
             
                checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn] )
         | 
| 94 | 
             
                # 整理反复出现的控件句柄组合
         | 
| 95 | 
             
                input_combo = [txt, top_p, temperature, chatbot, history, system_prompt]
         | 
| 96 | 
            -
                output_combo = [chatbot, history,  | 
| 97 | 
            -
                predict_args = dict(fn=predict, inputs=input_combo, outputs=output_combo | 
| 98 | 
             
                empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt]) # 用于在提交后清空输入栏
         | 
| 99 | 
             
                # 提交按钮、重置按钮
         | 
| 100 | 
             
                cancel_handles.append(txt.submit(**predict_args)) #; txt.submit(**empty_txt_args) 在提交后清空输入栏
         | 
| @@ -102,7 +102,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False, css=advanced_css) as de | |
| 102 | 
             
                resetBtn.click(lambda: ([], [], "已重置"), None, output_combo)
         | 
| 103 | 
             
                # 基础功能区的回调函数注册
         | 
| 104 | 
             
                for k in functional:
         | 
| 105 | 
            -
                    click_handle = functional[k]["Button"].click(predict, [*input_combo, gr.State(True), gr.State(k)], output_combo | 
| 106 | 
             
                    cancel_handles.append(click_handle)
         | 
| 107 | 
             
                # 文件上传区,接收文件后与chatbot的互动
         | 
| 108 | 
             
                file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
         | 
|  | |
| 54 | 
             
                            stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
         | 
| 55 | 
             
                        with gr.Row():
         | 
| 56 | 
             
                            from check_proxy import check_proxy
         | 
| 57 | 
            +
                            status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {check_proxy(proxies)}")
         | 
| 58 | 
             
                        with gr.Accordion("基础功能区", open=True) as area_basic_fn:
         | 
| 59 | 
             
                            with gr.Row():
         | 
| 60 | 
             
                                for k in functional:
         | 
|  | |
| 93 | 
             
                checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn] )
         | 
| 94 | 
             
                # 整理反复出现的控件句柄组合
         | 
| 95 | 
             
                input_combo = [txt, top_p, temperature, chatbot, history, system_prompt]
         | 
| 96 | 
            +
                output_combo = [chatbot, history, status]
         | 
| 97 | 
            +
                predict_args = dict(fn=predict, inputs=input_combo, outputs=output_combo)
         | 
| 98 | 
             
                empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt]) # 用于在提交后清空输入栏
         | 
| 99 | 
             
                # 提交按钮、重置按钮
         | 
| 100 | 
             
                cancel_handles.append(txt.submit(**predict_args)) #; txt.submit(**empty_txt_args) 在提交后清空输入栏
         | 
|  | |
| 102 | 
             
                resetBtn.click(lambda: ([], [], "已重置"), None, output_combo)
         | 
| 103 | 
             
                # 基础功能区的回调函数注册
         | 
| 104 | 
             
                for k in functional:
         | 
| 105 | 
            +
                    click_handle = functional[k]["Button"].click(predict, [*input_combo, gr.State(True), gr.State(k)], output_combo)
         | 
| 106 | 
             
                    cancel_handles.append(click_handle)
         | 
| 107 | 
             
                # 文件上传区,接收文件后与chatbot的互动
         | 
| 108 | 
             
                file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
         | 
    	
        toolbox.py
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 | 
             
            import markdown, mdtex2html, threading, importlib, traceback, importlib, inspect, re
         | 
| 2 | 
             
            from show_math import convert as convert_math
         | 
| 3 | 
            -
            from functools import wraps
         | 
| 4 |  | 
| 5 | 
             
            def get_reduce_token_percent(text):
         | 
| 6 | 
             
                try:
         | 
| @@ -289,22 +289,33 @@ def on_report_generated(files, chatbot): | |
| 289 | 
             
                chatbot.append(['汇总报告如何远程获取?', '汇总报告已经添加到右侧“文件上传区”(可能处于折叠状态),请查收。'])
         | 
| 290 | 
             
                return report_files, chatbot
         | 
| 291 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 292 | 
             
            def get_conf(*args):
         | 
| 293 | 
             
                # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
         | 
| 294 | 
             
                res = []
         | 
| 295 | 
             
                for arg in args:
         | 
| 296 | 
            -
                     | 
| 297 | 
            -
                    except: r = getattr(importlib.import_module('config'), arg)
         | 
| 298 | 
             
                    res.append(r)
         | 
| 299 | 
            -
                    # 在读取API_KEY时,检查一下是不是忘了改config
         | 
| 300 | 
            -
                    if arg=='API_KEY':
         | 
| 301 | 
            -
                        # 正确的 API_KEY 是 "sk-" + 48 位大小写字母数字的组合
         | 
| 302 | 
            -
                        API_MATCH = re.match(r"sk-[a-zA-Z0-9]{48}$", r)
         | 
| 303 | 
            -
                        if API_MATCH:
         | 
| 304 | 
            -
                            print(f"您的 API_KEY 是: {r[:15]}*** \nAPI_KEY 导入成功")
         | 
| 305 | 
            -
                        else:
         | 
| 306 | 
            -
                            assert False, "正确的 API_KEY 是 'sk-' + '48 位大小写字母数字' 的组合,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
         | 
| 307 | 
            -
                                        "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
         | 
| 308 | 
             
                return res
         | 
| 309 |  | 
| 310 | 
             
            def clear_line_break(txt):
         | 
|  | |
| 1 | 
             
            import markdown, mdtex2html, threading, importlib, traceback, importlib, inspect, re
         | 
| 2 | 
             
            from show_math import convert as convert_math
         | 
| 3 | 
            +
            from functools import wraps, lru_cache
         | 
| 4 |  | 
| 5 | 
             
            def get_reduce_token_percent(text):
         | 
| 6 | 
             
                try:
         | 
|  | |
| 289 | 
             
                chatbot.append(['汇总报告如何远程获取?', '汇总报告已经添加到右侧“文件上传区”(可能处于折叠状态),请查收。'])
         | 
| 290 | 
             
                return report_files, chatbot
         | 
| 291 |  | 
| 292 | 
            +
            @lru_cache
         | 
| 293 | 
            +
            def read_single_conf_with_lru_cache(arg):
         | 
| 294 | 
            +
                try: r = getattr(importlib.import_module('config_private'), arg)
         | 
| 295 | 
            +
                except: r = getattr(importlib.import_module('config'), arg)
         | 
| 296 | 
            +
                # 在读取API_KEY时,检查一下是不是忘了改config
         | 
| 297 | 
            +
                if arg=='API_KEY':
         | 
| 298 | 
            +
                    # 正确的 API_KEY 是 "sk-" + 48 位大小写字母数字的组合
         | 
| 299 | 
            +
                    API_MATCH = re.match(r"sk-[a-zA-Z0-9]{48}$", r)
         | 
| 300 | 
            +
                    if API_MATCH:
         | 
| 301 | 
            +
                        print(f"[API_KEY] 您的 API_KEY 是: {r[:15]}*** API_KEY 导入成功")
         | 
| 302 | 
            +
                    else:
         | 
| 303 | 
            +
                        assert False, "正确的 API_KEY 是 'sk-' + '48 位大小写字母数字' 的组合,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
         | 
| 304 | 
            +
                                    "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
         | 
| 305 | 
            +
                if arg=='proxies':
         | 
| 306 | 
            +
                    if r is None: 
         | 
| 307 | 
            +
                        print('[PROXY] 网络代理状态:未配置。无代理状态下很可能无法访问。建议:检查USE_PROXY选项是否修改。')
         | 
| 308 | 
            +
                    else: 
         | 
| 309 | 
            +
                        print('[PROXY] 网络代理状态:已配置。配置信息如下:', r)
         | 
| 310 | 
            +
                        assert isinstance(r, dict), 'proxies格式错误,请注意proxies选项的格式,不要遗漏括号。'
         | 
| 311 | 
            +
                return r
         | 
| 312 | 
            +
             | 
| 313 | 
             
            def get_conf(*args):
         | 
| 314 | 
             
                # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
         | 
| 315 | 
             
                res = []
         | 
| 316 | 
             
                for arg in args:
         | 
| 317 | 
            +
                    r = read_single_conf_with_lru_cache(arg)
         | 
|  | |
| 318 | 
             
                    res.append(r)
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 319 | 
             
                return res
         | 
| 320 |  | 
| 321 | 
             
            def clear_line_break(txt):
         |