Deploying Streamlit Applications on Hugging Face
Last updated July 1, 2024
Introduction: Streamlit is a powerful and easy-to-use framework for creating interactive web applications with Python. Hugging Face Spaces support deploying Streamlit apps, allowing you to share interactive models and visualizations effortlessly.
Steps:
- Install Streamlit
- Ensure Streamlit is installed pip install streamlit
2.Create a Basic Streamlit App
- Example App Code import streamlit as st from transformers import pipeline st.title('Sentiment Analysis with Hugging Face') model = pipeline('sentiment-analysis') user_input = st.text_area("Enter text for sentiment analysis:") if st.button('Analyze'): result = model(user_input) st.write(result)
3.Deploy Your Streamlit App on Hugging Face Spaces
- Set Up Your Space:
- Log in to Hugging Face and create a new Space, selecting Streamlit as the SDK.
- Push Your Code git init git add . git commit -m "Initial commit" git remote add origin https://huggingface.co/spaces/your_username/your_space_name git push -u origin main
4.Customize Your Streamlit App
- Add Widgets and Visualizations
import matplotlib.pyplot as plt import numpy as np st.title('Interactive Data Visualization') x = np.linspace(0, 10, 100) y = np.sin(x) fig, ax = plt.subplots() ax.plot(x, y) st.pyplot(fig)
Was this article helpful?