import gradio as gr import os from te_u.arxiv import get_news_from_arxiv # # os.environ['http_proxy'] = '127.0.0.1:7890' # os.environ['https_proxy'] = '127.0.0.1:7890' from utils import get_news, get_clouds from gradio_pdf import PDF current_pdf_file = None news = [] choose_news = [] with gr.Blocks() as demo: with gr.Row(): with gr.Column(scale=20): gr.HTML("""

科研情报

""") with gr.Column(scale=1, min_width=100): gr.HTML( """
""" ) gr.HTML( """
Created by 朱瑞
""" ) with gr.Tabs(elem_classes="tab-buttons") as tabs: with gr.TabItem("科研文献分析"): with gr.Row(): with gr.Accordion("文献采集区", open=True, ) as area_news_get_fn: keywords = gr.Dropdown(choices=["对抗攻击", "knowledge graph", "认知智能与先进计算", "电磁空间感知与利用", "信息安全与攻防博弈"], value="对抗攻击", label="关键词", show_label=True) source = gr.Dropdown(choices=["知网", "arxiv"], value="知网", label="数据源", show_label=True) num = gr.Slider(1, 100, value=10, label="采集条数", step=1) news_get = gr.Button("获取论文", variant='primary') with gr.Row(): with gr.Accordion("文献标记分析区", open=True, elem_id="news-panel") as news_get_fn: chosen_news = gr.CheckboxGroup(choices=[item['name'] for item in news], label="需要进行操作的文献") with gr.Row(): news_mark = gr.Button("标记文献") news_all_mark = gr.Button("全部标记", variant='primary') def recover_news_by_choose(news_titles): select_news = [] global news for news_title in news_titles: for i in news: if news_title == i['name']: new_i = i select_news.append(new_i) break return select_news def mark_new(titles): global choose_news mark_news = recover_news_by_choose(titles) choose_news = mark_news def get_news_temp(num, keywords, source): """ 获取临时的文献 """ global news results = [] if source == "知网": results = get_news(num, keywords) elif source == "arxiv": results = get_news_from_arxiv(num, keywords) news.extend(results) return gr.CheckboxGroup(choices=[item['name'] for item in news], label="需要进行操作的文献") def mark_all_new(): global news global choose_news choose_news = news return gr.CheckboxGroup(choices=[item['name'] for item in news], value=[item['name'] for item in news], label="需要进行操作的文献") news_get.click(get_news_temp, inputs=[num, keywords, source], outputs=[chosen_news]) news_mark.click(mark_new, inputs=[chosen_news]) news_all_mark.click(mark_all_new, outputs=[chosen_news]) with gr.TabItem("科研文献获取"): with gr.Row(): with gr.Accordion("功能区", open=True, ) as area_news_analyse_fn: with gr.Row(): ci_yun_by_title = gr.Button("题目词云", variant='primary') ci_yun_by_abstract = gr.Button("摘要词云", variant='primary') with gr.Row(): with gr.Accordion("结果展示区", open=True, ) as area_news_result_fn: result_place = gr.Image() def g_ci_yun_by_title(): global choose_news word_list = [c["name"] for c in choose_news] pic = get_clouds(word_list) return pic def g_ci_yun_by_abstract(): global choose_news word_list = [c["abstract"] for c in choose_news] pic = get_clouds(word_list) return pic ci_yun_by_title.click(g_ci_yun_by_title, outputs=[result_place]) ci_yun_by_abstract.click(g_ci_yun_by_abstract, outputs=[result_place]) with gr.TabItem("会议论文查看"): with gr.Row(): with gr.Column(scale=1): with gr.Row(): # gr.Label("会议名称") conf_name = gr.Dropdown(choices=["ECCV2022", "ECCV2020", "CVPR2024"], value="ECCV2022", label="会议名称", show_label=True) conf_button = gr.Button("查看会议论文", variant='primary') dataframe = gr.Dataframe(headers=["论文名称"], col_count=(1, "fixed"), type='array', height=800) with gr.Row(): look_input = gr.Textbox(placeholder="关键词检索", label="关键词过滤") filter_button = gr.Button("过滤") # up_button = gr.Button("加载") with gr.Column(scale=2): pdf = PDF(label="Upload a PDF", interactive=True, height=1000) # name = gr.Textbox(show_label=False) # pdf.upload(lambda f: f, pdf, name) def up_load(): global current_pdf_file n = r"D:\py\keyan_qingbao\te_u\paper_down_load\ECCV_2022\main_paper\3d-siamese-transformer-network-for-single-object-tracking-on-point-clouds_ECCV_2022.pdf" current_pdf_file = n return n def load_conf_list(conf_name): if conf_name == "ECCV2022": root_dir = r"D:\py\keyan_qingbao\te_u\paper_down_load\ECCV_2022\main_paper" return [[i] for i in os.listdir(root_dir)] def look_dataframe(evt: gr.SelectData): global current_pdf_file if evt.value: root_dir = r"D:\py\keyan_qingbao\te_u\paper_down_load\ECCV_2022\main_paper" n = os.path.join(root_dir, evt.value) if os.path.exists(n): current_pdf_file = n return current_pdf_file def filter_by_word(words, paper_list): word_list = words.strip().split() paper_list_filter = [p[0] for p in paper_list] for word in word_list: paper_list_filter = [p for p in paper_list_filter if word in p] return [[p] for p in paper_list_filter] filter_button.click(filter_by_word, inputs=[look_input, dataframe], outputs=[dataframe]) dataframe.select(look_dataframe, inputs=None, outputs=[pdf]) conf_button.click(load_conf_list, inputs=[conf_name], outputs=[dataframe]) # up_button.click(up_load, inputs=None, outputs=[pdf])s if __name__ == '__main__': demo.queue().launch(inbrowser=True, server_name='127.0.0.1', server_port=23223)