Benjamin Bossan commited on
Commit
3d6a12e
1 Parent(s): 5757778

Add simple gradio web interface

Browse files
Files changed (3) hide show
  1. README.md +8 -0
  2. demo.py +55 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -38,6 +38,14 @@ uvicorn src.gistillery.webservice:app --reload --port 8080
38
 
39
  For example requests, check `requests.org`.
40
 
 
 
 
 
 
 
 
 
41
  ## Checks
42
 
43
  ### Running tests
 
38
 
39
  For example requests, check `requests.org`.
40
 
41
+ A very simple web interface is available via gradio. To start it, run:
42
+
43
+ ```sh
44
+ python demo.py
45
+ ```
46
+
47
+ and navigate to the indicated URL (usually http://127.0.0.1:7860).
48
+
49
  ## Checks
50
 
51
  ### Running tests
demo.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import httpx
2
+ import gradio as gr
3
+
4
+
5
+ client = httpx.Client()
6
+
7
+
8
+ def submit(inputs):
9
+ payload = {"content": inputs, "author": "anna nymous"}
10
+ httpx.post("http://localhost:8080/submit/", json=payload)
11
+
12
+
13
+ def check_status():
14
+ response = httpx.get("http://localhost:8080/check_job_status/")
15
+ return response.json()
16
+
17
+
18
+ def get_results():
19
+ response = httpx.get("http://localhost:8080/recent/")
20
+ entries = response.json()
21
+ texts: list[str] = []
22
+ for i, entry in enumerate(entries, start=1):
23
+ texts.append(
24
+ f"## {i}. author: {entry['author']}\n\n"
25
+ f"Date: _{entry['date']}_\n\n"
26
+ f"**Summary**: {entry['summary']}\n\n"
27
+ f"tags: _{' '.join(entry['tags'])}_"
28
+ )
29
+ return "\n\n---\n\n".join(texts)
30
+
31
+
32
+ def get_demo():
33
+ with gr.Blocks() as demo:
34
+ # submit new input
35
+ inputs = gr.Textbox(lines=3, label="Input (text, URL)")
36
+ btn_submit = gr.Button("Submit")
37
+
38
+ # check job status
39
+ status = gr.Label("Status: ")
40
+ btn_status = gr.Button("Check Status")
41
+
42
+ # display output
43
+ btn_output = gr.Button("Show results")
44
+ output = gr.Markdown()
45
+
46
+ btn_submit.click(submit, inputs=inputs)
47
+ btn_status.click(check_status, outputs=[status])
48
+ btn_output.click(get_results, outputs=[output])
49
+
50
+ return demo
51
+
52
+
53
+ if __name__ == "__main__":
54
+ demo = get_demo()
55
+ demo.launch()
requirements.txt CHANGED
@@ -7,3 +7,4 @@ accelerate
7
  charset-normalizer
8
  trafilatura
9
  pillow
 
 
7
  charset-normalizer
8
  trafilatura
9
  pillow
10
+ gradio