Spaces:
Runtime error
Runtime error
Yasin Yousif
commited on
Commit
·
9cf758a
1
Parent(s):
278dc7f
Add application file
Browse files- .gitattributes +8 -23
- README.md +20 -7
- README1.md +25 -0
- app.py +39 -0
- out.bin +3 -0
- requirements.txt +31 -0
- story.py +36 -0
.gitattributes
CHANGED
@@ -1,31 +1,16 @@
|
|
1 |
-
*.
|
2 |
-
*.
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
21 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
23 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
26 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
1 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
4 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.tar.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
11 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
|
|
12 |
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
15 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
16 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
@@ -1,13 +1,26 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license: bsd
|
11 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
|
|
|
1 |
---
|
2 |
+
title: YOLOv5
|
3 |
+
emoji: 🐨
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: gray
|
6 |
sdk: gradio
|
|
|
7 |
app_file: app.py
|
8 |
pinned: false
|
|
|
9 |
---
|
10 |
+
# Configuration
|
11 |
+
`title`: _string_
|
12 |
+
Display title for the Space
|
13 |
+
`emoji`: _string_
|
14 |
+
Space emoji (emoji-only character allowed)
|
15 |
+
`colorFrom`: _string_
|
16 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
17 |
+
`colorTo`: _string_
|
18 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
19 |
+
`sdk`: _string_
|
20 |
+
Can be either `gradio` or `streamlit`
|
21 |
+
`app_file`: _string_
|
22 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
23 |
+
Path is relative to the root of the repository.
|
24 |
|
25 |
+
`pinned`: _boolean_
|
26 |
+
Whether the Space stays on top of your list.
|
README1.md
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# reddit-short-stories
|
2 |
+
A small unlabelled dataset of 4,308 short stories (4 million words) scraped from https://reddit.com/r/WritingPrompts for your machine learning needs.
|
3 |
+
|
4 |
+
Scraped and formatted by Trevor Du
|
5 |
+
|
6 |
+
## Dataset description
|
7 |
+
* Each line of [reddit_short_stories.txt](https://github.com/tdude92/reddit-short-stories/blob/main/reddit_short_stories.txt) is one full short story.
|
8 |
+
* Each short story begins with an "\<sos>" token and ends with an "\<eos>" token (eg. "\<sos> once upon a time, the end \<eos>").
|
9 |
+
* Newline characters in a story are replaced with the "\<nl>" token (eg. "\<sos> line 1 \<nl> line 2 \<eos>")
|
10 |
+
|
11 |
+
## Data Collection Method
|
12 |
+
r/WritingPrompts is a forum on the popular discussion website, https://reddit.com. The tradition is that users start threads that are titled with a *Writing Prompt*. In these threads, other users comment a short story they've written based on the original prompt.
|
13 |
+
|
14 |
+
The scraper saved a comment on a post on r/WritingPrompts if the following conditions are satisfied:
|
15 |
+
* The post is flaired "Writing Prompt"
|
16 |
+
* The post has >=1.0k upvotes.
|
17 |
+
* The author of the comment is not a moderator of r/WritingPrompts (to avoid scraping automod posts and mod announcements).
|
18 |
+
* The comment has >=200 upvotes.
|
19 |
+
* The comment has >=200 words.
|
20 |
+
* <20 comments have already been scraped from the comment's parent post.
|
21 |
+
|
22 |
+
Note: Only a portion of r/WritingPrompts was scraped, not the entire thing.
|
23 |
+
|
24 |
+
Hoping to scrape more of r/WritingPrompts and other subreddits in the future.
|
25 |
+
|
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
from story import story_model
|
5 |
+
|
6 |
+
# Images
|
7 |
+
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
|
8 |
+
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/bus.jpg', 'bus.jpg')
|
9 |
+
|
10 |
+
# Model
|
11 |
+
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # force_reload=True to update
|
12 |
+
|
13 |
+
|
14 |
+
def yolo(im, size=640):
|
15 |
+
g = (size / max(im.size)) # gain
|
16 |
+
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
17 |
+
|
18 |
+
results = model(im) # inference
|
19 |
+
|
20 |
+
r= results.pred[0].numpy().T
|
21 |
+
#probs = results.pred[0].numpy().T[-1]
|
22 |
+
res = [(results.names[x].lower(),p) for x,p in zip(r[-1].astype(int),r[-2].numpy())]
|
23 |
+
f_res = story_model(res)
|
24 |
+
#results.render() # updates results.imgs with boxes and labels
|
25 |
+
#return Image.fromarray(results.imgs[0])
|
26 |
+
return ','.join(f_res)
|
27 |
+
|
28 |
+
|
29 |
+
inputs = gr.inputs.Image(type='pil', label="Original Image")
|
30 |
+
#outputs = gr.outputs.Image(type="pil", label="Output Image")
|
31 |
+
outputs = gr.outputs.Textbox(type="text", label="Output Story")
|
32 |
+
|
33 |
+
title = "YOLOv5"
|
34 |
+
description = "YOLOv5 Gradio demo for object detection. Upload an image or click an example image to use."
|
35 |
+
article = "<p style='text-align: center'>YOLOv5 is a family of compound-scaled object detection models trained on the COCO dataset, and includes simple functionality for Test Time Augmentation (TTA), model ensembling, hyperparameter evolution, and export to ONNX, CoreML and TFLite. <a href='https://github.com/ultralytics/yolov5'>Source code</a> | <a href='https://pytorch.org/hub/ultralytics_yolov5'>PyTorch Hub</a></p>"
|
36 |
+
|
37 |
+
examples = [['zidane.jpg'], ['bus.jpg']]
|
38 |
+
iface = gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, theme="huggingface").launch(cache_examples=True,enable_queue=True)
|
39 |
+
iface.launch()
|
out.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7ba44ea6fae2933f07a95c2795bc87542728b25228e6f051dc13fae0b895ef7d
|
3 |
+
size 10047404
|
requirements.txt
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# pip install -r requirements.txt
|
2 |
+
|
3 |
+
# base ----------------------------------------
|
4 |
+
matplotlib>=3.2.2
|
5 |
+
numpy>=1.18.5
|
6 |
+
opencv-python-headless
|
7 |
+
Pillow
|
8 |
+
PyYAML>=5.3.1
|
9 |
+
scipy>=1.4.1
|
10 |
+
torch>=1.7.0
|
11 |
+
torchvision>=0.8.1
|
12 |
+
tqdm>=4.41.0
|
13 |
+
|
14 |
+
# logging -------------------------------------
|
15 |
+
tensorboard>=2.4.1
|
16 |
+
# wandb
|
17 |
+
|
18 |
+
# plotting ------------------------------------
|
19 |
+
seaborn>=0.11.0
|
20 |
+
pandas
|
21 |
+
|
22 |
+
# export --------------------------------------
|
23 |
+
# coremltools>=4.1
|
24 |
+
# onnx>=1.9.0
|
25 |
+
# scikit-learn==0.19.2 # for coreml quantization
|
26 |
+
|
27 |
+
# extras --------------------------------------
|
28 |
+
# Cython # for pycocotools https://github.com/cocodataset/cocoapi/issues/172
|
29 |
+
# pycocotools>=2.0 # COCO mAP
|
30 |
+
# albumentations>=1.0.3
|
31 |
+
thop # FLOPs computation
|
story.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
import numpy as np
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
|
6 |
+
def load_sentense_data():
|
7 |
+
min_sent_length = 20
|
8 |
+
|
9 |
+
All_sentenses = []
|
10 |
+
with open('reddit_short_stories.txt','r') as f:
|
11 |
+
stories = f.readlines()
|
12 |
+
|
13 |
+
for story in stories:
|
14 |
+
L = story.split('<nl> _____________ <nl>')[0]
|
15 |
+
|
16 |
+
|
17 |
+
L=L.strip('<sos>').strip('" <eos>')
|
18 |
+
|
19 |
+
L=re.split('; |, |\.|\*|\n|<nl>',L)
|
20 |
+
|
21 |
+
All_sentenses.extend([x.lower() for x in L if len(x)>min_sent_length])
|
22 |
+
|
23 |
+
return All_sentenses
|
24 |
+
|
25 |
+
|
26 |
+
def story_model(preds,res_len=5):
|
27 |
+
with open("out.bin", "rb") as fp:
|
28 |
+
All_sentenses = pickle.load(fp)
|
29 |
+
#All_sentenses = load_sentense_data()
|
30 |
+
dists = np.zeros(len(All_sentenses))
|
31 |
+
for word,prob in preds:
|
32 |
+
dists += np.array([prob * (word in sent) for sent in All_sentenses])
|
33 |
+
|
34 |
+
f_res = list(zip(dists,All_sentenses)).sort(key=lambda x:x[1])[-res_len:]
|
35 |
+
|
36 |
+
return f_res # list of sentenses
|