File size: 1,349 Bytes
3d6a12e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c028cc
3d6a12e
 
 
 
 
 
 
 
 
 
 
 
 
5c028cc
3d6a12e
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
import httpx
import gradio as gr


client = httpx.Client()


def submit(inputs):
    payload = {"content": inputs, "author": "anna nymous"}
    httpx.post("http://localhost:8080/submit/", json=payload)


def check_status():
    response = httpx.get("http://localhost:8080/check_job_status/")
    return response.json()


def get_results():
    response = httpx.get("http://localhost:8080/recent/")
    entries = response.json()
    texts: list[str] = []
    for i, entry in enumerate(entries, start=1):
        texts.append(
            f"## {i}. author: {entry['author']}\n\n"
            f"Date: _{entry['date']}_\n\n"
            f"**Summary**: {entry['summary']}\n\n"
            f"tags: _{' '.join(entry['tags'])}_"
        )
    return "\n\n---\n\n".join(texts)


def get_demo():
    with gr.Blocks() as demo:
        # submit new input
        inputs = gr.Textbox(lines=3, label="Input (text, URL)")
        btn_submit = gr.Button("Submit")

        # check job status
        gr.HTML(value=check_status, label="Status", every=3)

        # display output
        btn_output = gr.Button("Show results")
        output = gr.Markdown()

        btn_submit.click(submit, inputs=inputs)
        btn_output.click(get_results, outputs=[output])

    return demo


if __name__ == "__main__":
    demo = get_demo()
    demo.queue()
    demo.launch()