Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,58 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from duckduckgo_search import DDGS
|
| 3 |
+
from fastcore.all import *
|
| 4 |
|
| 5 |
+
ddgs = DDGS()
|
|
|
|
| 6 |
|
| 7 |
+
def search_images(term, max_images=30):
|
| 8 |
+
print(f"Searching for '{term}'")
|
| 9 |
+
return L(ddgs.images(term, max_results=max_images)).itemgot('image')
|
| 10 |
+
|
| 11 |
+
#NB: `search_images` depends on duckduckgo.com, which doesn't always return correct responses.
|
| 12 |
+
# If you get a JSON error, just try running it again (it may take a couple of tries).
|
| 13 |
+
urls = search_images('beaver photos', max_images=1)
|
| 14 |
+
urls[0]
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
from fastdownload import download_url
|
| 19 |
+
dest = 'beaver.jpg'
|
| 20 |
+
download_url(urls[0], dest, show_progress=False)
|
| 21 |
+
|
| 22 |
+
from fastai.vision.all import *
|
| 23 |
+
im = Image.open(dest)
|
| 24 |
+
im.to_thumb(256,256)
|
| 25 |
+
|
| 26 |
+
download_url(search_images('platypus photo', max_images=1)[0], 'platypus.jpg', show_progress=False)
|
| 27 |
+
Image.open('platypus.jpg').to_thumb(256,256)
|
| 28 |
+
|
| 29 |
+
download_url(search_images('platypus photo', max_images=1)[0], 'platypus.jpg', show_progress=False)
|
| 30 |
+
Image.open('platypus.jpg').to_thumb(256,256)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
failed = verify_images(get_image_files(path))
|
| 34 |
+
failed.map(Path.unlink)
|
| 35 |
+
len(failed)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
dls = DataBlock(
|
| 39 |
+
blocks=(ImageBlock, CategoryBlock),
|
| 40 |
+
get_items=get_image_files,
|
| 41 |
+
splitter=RandomSplitter(valid_pct=0.2, seed=42),
|
| 42 |
+
get_y=parent_label,
|
| 43 |
+
item_tfms=[Resize(192, method='squish')]
|
| 44 |
+
).dataloaders(path, bs=32)
|
| 45 |
+
|
| 46 |
+
dls.show_batch(max_n=6)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
learn = vision_learner(dls, resnet18, metrics=error_rate)
|
| 50 |
+
learn.fine_tune(3)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
is_sheep,_,probs = learn.predict(PILImage.create('beaver.jpg'))
|
| 54 |
+
print(f"This is a: {is_sheep}.")
|
| 55 |
+
print(f"Probability it's a beaver: {probs[0]:.4f}")
|
| 56 |
+
|
| 57 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 58 |
demo.launch()
|