File size: 3,108 Bytes
fe0ce42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
import os
import gradio as gr
from suggest import Suggest
from edit import Editor
from config import configure_logging


configure_logging()


with gr.Blocks() as demo:
    
    title = gr.Button("PaperGPT", interactive=False)
    key = gr.Textbox(label="openai_key", value=os.environ.get('OPENAI_API_KEY'))
    
    with gr.Tab("Edit"):
        
        handler = Editor()
        txt_in = gr.Textbox(label="Input", lines=11, max_lines=11, value=handler.sample_content)
        btn = gr.Button("Edit")
        txt_out = gr.Textbox(label="Output", lines=11, max_lines=11, value="GPT will serve as your editor and modify the paragraph for you.")
        btn.click(handler.generate, inputs=[txt_in, key], outputs=[txt_out])
    
    with gr.Tab("Suggest"):
        
        idea_list = []
        max_ideas = 20
        handler = Suggest(max_ideas)

        def select(name: str):
            global idea_list
            for i in idea_list:
                if i['title'] == name:
                    return [
                        gr.Textbox.update(value=i["thought"], label="thought", visible=True),
                        gr.Textbox.update(value=i["action"], label="action", visible=True),
                        gr.Textbox.update(value=i["original"], label="original", visible=True, max_lines=5, lines=5),
                        gr.Textbox.update(value=i["improved"], label="improved", visible=True, max_lines=5, lines=5)
                    ]

        with gr.Row().style(equal_height=True):
            with gr.Column(scale=0.95):
                txt_in = gr.Textbox(label="Input", lines=11, max_lines=11, value=handler.sample_content[2048+2048+256-45:])
            with gr.Column(scale=0.05):
                upload = gr.File(file_count="single", file_types=["tex", ".pdf"])
                btn = gr.Button("Analyze")
                upload.change(handler.read_file, inputs=upload, outputs=txt_in)

        textboxes = []
        sug = gr.Textbox("GPT will give suggestions and help you improve the paper quality.", interactive=False, show_label=False).style(text_align="center")
        with gr.Row():
            with gr.Column(scale=0.4):
                for i in range(max_ideas):
                    t = gr.Button("", visible=False)
                    textboxes.append(t)
            with gr.Column(scale=0.6):
                thought = gr.Textbox(label="thought", visible=False, interactive=False)
                action = gr.Textbox(label="action", visible=False, interactive=False)
                original = gr.Textbox(label="original", visible=False, max_lines=5, lines=5, interactive=False)
                improved = gr.Textbox(label="improved", visible=False, max_lines=5, lines=5, interactive=False)

        btn.click(handler.generate, inputs=[txt_in, key], outputs=[sug, btn, thought, action, original, improved] + textboxes)
        for i in textboxes:
            i.click(select, inputs=[i], outputs=[thought, action, original, improved])
            

    # demo.launch(server_name="0.0.0.0", server_port=7653, share=True, enable_queue=True)
    demo.launch(enable_queue=True)