osanseviero HF staff commited on
Commit
a7db2b1
β€’
1 Parent(s): fd82a33

Finish article 1

Browse files
app.py CHANGED
@@ -3,10 +3,6 @@ import re
3
  from pathlib import Path
4
  import importlib
5
 
6
- import yaml
7
-
8
- REGEX_YAML_BLOCK = re.compile(r"---[\n\r]+([\S\s]*?)[\n\r]+---[\n\r](.*)", re.DOTALL)
9
-
10
 
11
  def render_preview(image, title, description):
12
  with st.container():
 
3
  from pathlib import Path
4
  import importlib
5
 
 
 
 
 
6
 
7
  def render_preview(image, title, description):
8
  with st.container():
assets/1_huggingface_logo.png DELETED
Binary file (11 kB)
 
assets/1_thumbnail.png ADDED
posts/1_blog_in_spaces.py CHANGED
@@ -1,37 +1,43 @@
1
- from email.mime import image
2
  import streamlit as st
3
 
 
 
 
4
  title = "T&T1 - Create interactive blog posts with Streamlit and Spaces"
5
  description = "Learn about how to host interactive blogs using Streamlit, GitHub and Spaces."
6
  date = "2022-01-20"
7
- thumbnail = "assets/1_huggingface_logo.png"
8
 
9
  def run_article():
10
  st.markdown("""
11
  # πŸ€— Tips & Tricks Edition 1
12
  # Create interactive blog posts with Streamlit and Spaces
13
 
14
- Welcome to the first post of the πŸ€— Tips and Tricks blog! In this blog, I'll be sharing features you might not know about to leverage the Hub platform and Open Source ecosystem at its full extent.
 
 
15
 
16
- In today's post, you'll learn how this blog was actually done! This is actually very easy and the setup takes less than 10 minutes!
17
 
18
- ## Workflow
19
 
20
- I'm a strong believer that there are different tools for different jobs. The tools we'll use today are:
21
 
22
  * **Streamlit**: A very cool Open Source library that allows to build apps in Python in a very straightforward way.
23
- * **GitHub**: The main platform in which we're going to be doing the coding.
24
- * **Hugging Face Hub**: The platform in which the demo will be hosted using [Spaces](http://hf.co/spaces/launch), a platform through which you can freely share ML demos using Streamlit, Gradio or even static sites (HTML & JavaScript if you're into that stuff).
 
 
25
 
26
- Note: this is not a fully-fledged blog platform. There won't be subscribe options, for example, but it's a cool proof of concept that can be interesting for certain interactive articles.
27
 
28
  **Sure sure...but how does it work?**
29
 
30
- So you will have a Streamlit-based application in which you'll have your articles. The code will be in GitHub, and through GitHub Action workflows, the blog will be automatically sync'ed to a Hugging Face Space.
31
 
32
  **Sounds fun, let's do it!**
33
 
34
- Cool! So Nate has built a [nice template](https://github.com/nateraw/host-a-blog-on-huggingface-spaces) we can already use out of the box. Isn't that cool? Let's begin by clicking that **Fork** button in GitHub. Nice, so you're getting ready. Let's quickly explore what we have here
35
 
36
  - **.github/workflows/**: There is a GitHub Actions workflow that will automatically sync to the Hugging Face Hub each time you push into the repo.
37
  - **images/**: Well...it contains images.
@@ -49,15 +55,17 @@ def run_article():
49
  st.markdown("""
50
  Yes, let's do it.
51
 
52
- First, create a [new Space](https://huggingface.co/new-space) at Hugging Face. You will need to specify the Streamlit SDK. Since it's still being setup, you can make it private so others don't see it. The Space can have any name you want.
53
 
54
  The second step is to create a [write token](https://huggingface.co/settings/token). This will allow GitHub to push whenever there are changes to the Space.
55
 
56
  Make sure to copy the token and...
57
 
58
- **I won't expose my token! They will hack me!**
59
 
60
  No worries, we'll be adding a **secret** in GitHub, which allows to add environment variables that can be accessed but not viewed by anyone. You can go to your **GitHub repo**, go to Settings -> SECRETS, and click ** New secret**. The name can be `HF_TOKEN` and the value is the one you got from the Hub.
 
 
61
  """)
62
 
63
  with col2:
@@ -67,7 +75,11 @@ def run_article():
67
 
68
 
69
  st.markdown("""
70
- Now, if you go to **workflows/sync-to-hub**, you'll see the last line makes a reference to the original repo Space and your token. Let's switch the path to your own Space.
 
 
 
 
71
 
72
  So I changed
73
 
@@ -91,7 +103,32 @@ def run_article():
91
 
92
  Well, you just finished the setup! There are a couple of places where you will want to change stuff and then write your first article. Once you're ready, you should make your Spaces repo public, share it in social media and get likes from the community!
93
 
94
- I hope this was useful! Until the next time!
 
 
 
 
95
 
96
- A Hacker Llama πŸ¦™
97
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
+ from stmol import showmol
4
+ import py3Dmol
5
+
6
  title = "T&T1 - Create interactive blog posts with Streamlit and Spaces"
7
  description = "Learn about how to host interactive blogs using Streamlit, GitHub and Spaces."
8
  date = "2022-01-20"
9
+ thumbnail = "assets/1_thumbnail.png"
10
 
11
  def run_article():
12
  st.markdown("""
13
  # πŸ€— Tips & Tricks Edition 1
14
  # Create interactive blog posts with Streamlit and Spaces
15
 
16
+ Welcome to the first post of the πŸ€— Tips and Tricks blog! Each post can be read in <5 minutes and shares features you might not know about that will allow you to leverage the Hub platform and Open Source ecosystem to its full extent.
17
+
18
+ In today's post, you'll learn how this blog was actually done! This is actually very easy and the initial setup takes less than 10 minutes!
19
 
20
+ **How much will it cost me? πŸ€‘ **
21
 
22
+ Nothing! We'll be using Open Source and free tools to achieve it.
23
 
24
+ I'm a strong believer that there are different tools for different jobs, so today you'll use:
25
 
26
  * **Streamlit**: A very cool Open Source library that allows to build apps in Python in a very straightforward way.
27
+ * **GitHub**: The main platform in which we're going to be hosting the code.
28
+ * **Hugging Face Hub**: The platform in which the demo will be hosted using [Spaces](http://hf.co/spaces/launch). Spaces is a platform through which you can freely share ML demos using Streamlit, Gradio or even static sites (HTML & JavaScript if you're into that stuff).
29
+
30
+ **This is cool! Will I get subscriptions, likes, RSS, comments, ...**
31
 
32
+ No 😒 this is not a fully-fledged blog platform. It's just a cool proof of concept that can be interesting for having interactive articles.
33
 
34
  **Sure sure...but how does it work?**
35
 
36
+ So you will have a Streamlit-based application in which you'll have your articles. The code will be in GitHub, and through GitHub Action workflows, the blog will be automatically sync'ed to a Hugging Face Space. All the way automated!
37
 
38
  **Sounds fun, let's do it!**
39
 
40
+ Cool! πŸ”₯ So Nate has built a [nice template](https://github.com/nateraw/host-a-blog-on-huggingface-spaces) we can already use out of the box. Isn't that cool? Let's begin by clicking that **Fork** button in GitHub. Let's quickly explore what we have here
41
 
42
  - **.github/workflows/**: There is a GitHub Actions workflow that will automatically sync to the Hugging Face Hub each time you push into the repo.
43
  - **images/**: Well...it contains images.
 
55
  st.markdown("""
56
  Yes, let's do it.
57
 
58
+ First, create a [new Space](https://huggingface.co/new-space) at Hugging Face. You will need to specify the Streamlit SDK. Since it's still being written, you can make it private so others don't see it. The Space can have any name you want.
59
 
60
  The second step is to create a [write token](https://huggingface.co/settings/token). This will allow GitHub to push whenever there are changes to the Space.
61
 
62
  Make sure to copy the token and...
63
 
64
+ **I won't expose my token! They will hack me! 🚨🚨🚨**
65
 
66
  No worries, we'll be adding a **secret** in GitHub, which allows to add environment variables that can be accessed but not viewed by anyone. You can go to your **GitHub repo**, go to Settings -> SECRETS, and click ** New secret**. The name can be `HF_TOKEN` and the value is the one you got from the Hub.
67
+
68
+ πŸ¦™
69
  """)
70
 
71
  with col2:
 
75
 
76
 
77
  st.markdown("""
78
+ **Ok this is actually not that hard**
79
+
80
+ I know!
81
+
82
+ Now, if you go to your GitHub repo, to **workflows/sync-to-hub**, you'll see the last line makes a reference to the original Space repository and your token variable. Let's switch the path to your own Space.
83
 
84
  So I changed
85
 
 
103
 
104
  Well, you just finished the setup! There are a couple of places where you will want to change stuff and then write your first article. Once you're ready, you should make your Spaces repo public, share it in social media and get likes from the community!
105
 
106
+ **Isn't this just the same as having my content in GitHub Pages?**
107
+
108
+ The cool thing of doing the blog post with Streamlit is that your blog posts can be interactive.
109
+
110
+ **I don't get it**
111
 
112
+ Check this example to interact with a protein visualization! This is directly in the blog article and leverages [great work](https://towardsdatascience.com/molecular-visualization-in-streamlit-using-rdkit-and-py3dmol-part-2-657d28152753) done by the open source community.
113
  """)
114
+
115
+ prot_str='1A2C,1BML,1D5M,1D5X,1D5Z,1D6E,1DEE,1E9F,1FC2,1FCC,1G4U,1GZS,1HE1,1HEZ,1HQR,1HXY,1IBX,1JBU,1JWM,1JWS'
116
+ prot_list=prot_str.split(',')
117
+ bcolor = st.color_picker('Pick A Color', '#6D73A6')
118
+ protein=st.selectbox('select protein',prot_list)
119
+ xyzview = py3Dmol.view(query='pdb:'+protein)
120
+ xyzview.setStyle({"stick":{'color':'spectrum'}})
121
+ xyzview.setBackgroundColor(bcolor)
122
+ showmol(xyzview, height = 500,width=800)
123
+
124
+ st.markdown("""
125
+ **🀯 cool**
126
+
127
+ Yes! Now imagine all the cool, ML interactive blogs you could have. You could nicely mix ML demos with great explanations in a very interactive way. Next time you release a model, you could embed it directly in the announcement article and readers would be able to try it out directly in their browsers!
128
+
129
+ I hope this was useful! Until the next time!
130
+
131
+ **A Hacker Llama πŸ¦™**
132
+
133
+ [osanseviero](https://twitter.com/osanseviero)
134
+ """)
posts/__pycache__/1_blog_in_spaces.cpython-37.pyc CHANGED
Binary files a/posts/__pycache__/1_blog_in_spaces.cpython-37.pyc and b/posts/__pycache__/1_blog_in_spaces.cpython-37.pyc differ
 
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  streamlit
2
  pyyaml
 
 
 
1
  streamlit
2
  pyyaml
3
+ py3Dmol
4
+ stmol==0.0.7