Spaces:
Running
Running
Commit
•
42eab19
1
Parent(s):
5a97797
add tutorial and more info (#1)
Browse files- add tutorial and more info (1e4cec09b164f97fef1bc3edd2e2bccb92c62f95)
Co-authored-by: Ahsen Khaliq <akhaliq@users.noreply.huggingface.co>
README.md
CHANGED
@@ -15,8 +15,93 @@ Welcome to the 21st EuroPython. We're the oldest and longest running volunteer-l
|
|
15 |
|
16 |
<h2 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">Hugging Face Gradio Hackathon 🤗 </h2>
|
17 |
<p class="lg:col-span-2">
|
18 |
-
Come Join us from July 13th to 17th for a Hackathon in person and online using Gradio and Hugging Face to build and host Machine Learning demos.
|
19 |
<img class="lg:col-span-2" src="https://i.imgur.com/N6sZ5CI.png" alt="Europython Banner" style="margin:10px">
|
20 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
|
|
|
15 |
|
16 |
<h2 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">Hugging Face Gradio Hackathon 🤗 </h2>
|
17 |
<p class="lg:col-span-2">
|
18 |
+
Come Join us from July 13th to 17th for a Hackathon in person and online using Gradio and Hugging Face to build and host Machine Learning demos. Find tutorial on getting started with Gradio on Hugging Face <a href="https://huggingface.co/blog/gradio-spaces" style="text-decoration: underline" target="_blank">here</a> and to get started with the new Gradio Blocks API <a href="https://gradio.app/introduction_to_blocks/" style="text-decoration: underline" target="_blank">here</a></p>
|
19 |
<img class="lg:col-span-2" src="https://i.imgur.com/N6sZ5CI.png" alt="Europython Banner" style="margin:10px">
|
20 |
</div>
|
21 |
+
<h3 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">Join organization by clicking <a href="https://huggingface.co/organizations/EuroPython2022/share/JsnIYMRMwWreVmnLQLpPJfqZBhtKKZnMGV" style="text-decoration: underline" target="_blank">here</a></h3>
|
22 |
+
|
23 |
+
|
24 |
+
<h4 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold" id="Prizes">Hugging Face Prizes</h4>
|
25 |
+
<ul class="lg:col-span-2" style="list-style: circle inside">
|
26 |
+
<li class="my-4">Top 5 spaces based on likes<ul class="lg:col-span-2" style="list-style: circle inside;padding-left: 40px;">
|
27 |
+
<li class="my-4">Swag from <a href="https://huggingface.myshopify.com/">Hugging Face merch shop</a>: t-shirt, hoodie, or mug of your choice</li>
|
28 |
+
</ul>
|
29 |
+
</li>
|
30 |
+
</ul>
|
31 |
+
|
32 |
+
<h3 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">LeaderBoard for Most Popular EuroPython Spaces</h3>
|
33 |
+
<p class="lg:col-span-2">See the <a href="https://huggingface.co/spaces/CVPR/Leaderboard" target="_blank" style="text-decoration:underline; font-weight:bold">EuroPython Leaderboard</a></p>
|
34 |
+
<h4 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">Hugging Face Spaces & Gradio for Showcasing your EuroPython ‘22 Demo
|
35 |
+
</h4>
|
36 |
+
<p class="lg:col-span-2">
|
37 |
+
In this tutorial, we will demonstrate how to showcase your demo with an easy to use web interface using the Gradio Python library and host it on Hugging Face Spaces so that conference attendees can easily find and try out your demos. Also, see <a href="https://gradio.app/introduction_to_blocks/" style="text-decoration: underline" target="_blank">https://gradio.app/introduction_to_blocks/</a>, for a more flexible way to build Gradio Demos
|
38 |
+
</p>
|
39 |
+
<h3 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">🚀 Create a Gradio Demo from your Model
|
40 |
+
</h3>
|
41 |
+
<p class="lg:col-span-2">
|
42 |
+
The first step is to create a web demo from your model. As an example, we will be creating a demo from an image classification model (called model) which we will be uploading to Spaces. The full code for steps 1-4 can be found in this <a href="https://colab.research.google.com/drive/1S6seNoJuU7_-hBX5KbXQV4Fb_bbqdPBk?usp=sharing" style="text-decoration: underline" target="_blank">colab notebook</a>.
|
43 |
+
</p><br />
|
44 |
+
|
45 |
+
<h3 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">1. Install the gradio library
|
46 |
+
</h3>
|
47 |
+
<p class="lg:col-span-2">
|
48 |
+
All you need to do is to run this in the terminal: <code>pip install gradio</code>
|
49 |
+
</p>
|
50 |
+
<br />
|
51 |
+
<h3 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">2. Define a function in your Python code that performs inference with your model on a data point and returns the prediction
|
52 |
+
</h3>
|
53 |
+
<p class="lg:col-span-2">
|
54 |
+
Here’s we define our image classification model prediction function in PyTorch (any framework, like TensorFlow, scikit-learn, JAX, or a plain Python will work as well):
|
55 |
+
<pre>
|
56 |
+
<code>def predict(inp):
|
57 |
+
|
58 |
+
inp = Image.fromarray(inp.astype('uint8'), 'RGB')
|
59 |
+
|
60 |
+
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
61 |
+
|
62 |
+
with torch.no_grad():
|
63 |
+
|
64 |
+
prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
|
65 |
+
|
66 |
+
return {labels[i]: float(prediction[i]) for i in range(1000)}
|
67 |
+
</code>
|
68 |
+
</pre>
|
69 |
+
</p>
|
70 |
+
|
71 |
+
<h3 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">3. Then create a Gradio Interface using the function and the appropriate input and output types
|
72 |
+
</h3>
|
73 |
+
<p class="lg:col-span-2">
|
74 |
+
For the image classification model from Step 2, it would like like this:
|
75 |
+
</p>
|
76 |
+
<pre>
|
77 |
+
<code>
|
78 |
+
inputs = gr.inputs.Image()
|
79 |
+
|
80 |
+
outputs = gr.outputs.Label(num_top_classes=3)
|
81 |
+
|
82 |
+
io = gr.Interface(fn=predict, inputs=inputs, outputs=outputs)
|
83 |
+
</code>
|
84 |
+
</pre>
|
85 |
+
<p class="lg:col-span-2">
|
86 |
+
If you need help creating a Gradio Interface for your model, check out the Gradio Getting Started guide.
|
87 |
+
</p>
|
88 |
+
|
89 |
+
<h3 class="my-8 lg:col-span-2" style="font-size:20px; font-weight:bold">4. Then launch() you Interface to confirm that it runs correctly locally (or wherever you are running Python)
|
90 |
+
</h3>
|
91 |
+
<pre>
|
92 |
+
<code>
|
93 |
+
io.launch()
|
94 |
+
</code>
|
95 |
+
</pre>
|
96 |
+
<p class="lg:col-span-2">
|
97 |
+
You should see a web interface like the following where you can drag and drop your data points and see the predictions:
|
98 |
+
</p>
|
99 |
+
<img class="lg:col-span-2" src="https://i.imgur.com/1hsIgJJ.png" alt="Gradio Interface" style="margin:10px">
|
100 |
+
</div>
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
|
106 |
|
107 |
|