Spaces:
Runtime error
Runtime error
Benjamin Bossan
commited on
Commit
·
31610d3
1
Parent(s):
c97eca4
Improve presentation of inputs in demo
Browse files
demo.py
CHANGED
|
@@ -2,18 +2,6 @@ import httpx
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
|
| 5 |
-
client = httpx.Client()
|
| 6 |
-
# TODO: update the tags somehow; re-fetching inside of check_status doesn't work
|
| 7 |
-
try:
|
| 8 |
-
tag_counts = {
|
| 9 |
-
key.strip("#"): val
|
| 10 |
-
for key, val in client.get("http://localhost:8080/tag_counts/").json().items()
|
| 11 |
-
if key.strip("#")
|
| 12 |
-
}
|
| 13 |
-
except httpx.ConnectError:
|
| 14 |
-
tag_counts = {}
|
| 15 |
-
|
| 16 |
-
|
| 17 |
def submit(inputs):
|
| 18 |
if not inputs:
|
| 19 |
return
|
|
@@ -30,11 +18,26 @@ def check_status():
|
|
| 30 |
return result
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def get_results(inputs: list[str]):
|
| 34 |
if not inputs:
|
| 35 |
response = httpx.get("http://localhost:8080/recent/")
|
| 36 |
else:
|
| 37 |
-
tags =
|
|
|
|
| 38 |
response = httpx.get("http://localhost:8080/recent/" + ",".join(tags))
|
| 39 |
entries = response.json()
|
| 40 |
texts: list[str] = []
|
|
@@ -48,11 +51,22 @@ def get_results(inputs: list[str]):
|
|
| 48 |
return "\n\n---\n\n".join(texts)
|
| 49 |
|
| 50 |
|
| 51 |
-
INPUT_DESCRIPTION = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
- plain text
|
| 53 |
- a URL to a webpage
|
| 54 |
- a URL to a youtube video (the video will be transcribed)
|
| 55 |
- a URL to an image (the image description will be used)
|
|
|
|
|
|
|
|
|
|
| 56 |
"""
|
| 57 |
|
| 58 |
|
|
@@ -65,12 +79,11 @@ def get_demo():
|
|
| 65 |
|
| 66 |
# check job status
|
| 67 |
gr.HTML(value=check_status, label="Status", every=3)
|
|
|
|
| 68 |
|
| 69 |
# check box of tags to filter on
|
| 70 |
-
|
| 71 |
-
tags = gr.
|
| 72 |
-
tag_choices, label="Filter on tags (no selection = all)"
|
| 73 |
-
)
|
| 74 |
|
| 75 |
# display output
|
| 76 |
btn_output = gr.Button("Show results")
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def submit(inputs):
|
| 6 |
if not inputs:
|
| 7 |
return
|
|
|
|
| 18 |
return result
|
| 19 |
|
| 20 |
|
| 21 |
+
def check_tags():
|
| 22 |
+
try:
|
| 23 |
+
tag_counts = {
|
| 24 |
+
key.strip("#"): val
|
| 25 |
+
for key, val in httpx.get("http://localhost:8080/tag_counts/").json().items()
|
| 26 |
+
if key.strip("#")
|
| 27 |
+
}
|
| 28 |
+
sorted_tags = sorted(list(tag_counts.items()), key=lambda tup: -tup[1])
|
| 29 |
+
result = "Most common tags: " + ", ".join(f"{t} ({c})" for t, c in sorted_tags[:5])
|
| 30 |
+
except httpx.ConnectError:
|
| 31 |
+
result = ""
|
| 32 |
+
return result
|
| 33 |
+
|
| 34 |
+
|
| 35 |
def get_results(inputs: list[str]):
|
| 36 |
if not inputs:
|
| 37 |
response = httpx.get("http://localhost:8080/recent/")
|
| 38 |
else:
|
| 39 |
+
tags = inputs.replace(",", " ").split()
|
| 40 |
+
tags = [tag.lstrip("#") for tag in tags]
|
| 41 |
response = httpx.get("http://localhost:8080/recent/" + ",".join(tags))
|
| 42 |
entries = response.json()
|
| 43 |
texts: list[str] = []
|
|
|
|
| 51 |
return "\n\n---\n\n".join(texts)
|
| 52 |
|
| 53 |
|
| 54 |
+
INPUT_DESCRIPTION = """# Gistillery
|
| 55 |
+
|
| 56 |
+
The no-fuss knowledge dump.
|
| 57 |
+
|
| 58 |
+
Paste information into the field below and submit, _Gistillery_ will create a
|
| 59 |
+
short summary and hashtags for it. Then show results for most recent entries,
|
| 60 |
+
optionally filtered by hashtag.
|
| 61 |
+
|
| 62 |
+
Input currently supports:
|
| 63 |
- plain text
|
| 64 |
- a URL to a webpage
|
| 65 |
- a URL to a youtube video (the video will be transcribed)
|
| 66 |
- a URL to an image (the image description will be used)
|
| 67 |
+
|
| 68 |
+
Processing can take a couple of minutes, the info box below gives an update on
|
| 69 |
+
how many jobs are in the queue.
|
| 70 |
"""
|
| 71 |
|
| 72 |
|
|
|
|
| 79 |
|
| 80 |
# check job status
|
| 81 |
gr.HTML(value=check_status, label="Status", every=3)
|
| 82 |
+
gr.HTML(value=check_tags, label="Status", every=10)
|
| 83 |
|
| 84 |
# check box of tags to filter on
|
| 85 |
+
msg = "Enter hashtags to filter on (comma separated if multiple)"
|
| 86 |
+
tags = gr.Textbox(label=msg)
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# display output
|
| 89 |
btn_output = gr.Button("Show results")
|