A Step by Step Guide to Deploy Streamlit App Using Cloudflared, BeautifulSoup, Pandas, Plotly for Real-Time Cryptocurrency Web Scraping and Visualization
www.marktechpost.com
In this tutorial, well walk through a reliable and hassle-free approach using Cloudflared, a tool by Cloudflare that provides a secure, publicly accessible link to your Streamlit app. By the end of this guide, we will achieve a fully functional cryptocurrency dashboard that dynamically scrapes and visualizes real-time price data from CoinMarketCap. You can track the top 10 cryptocurrencies, compare their prices and market capitalizations, and view interactive charts for better insights.!pip install streamlit requests beautifulsoup4 pandas matplotlib plotly!npm install -g localtunnelFirst, the above command installs the necessary dependencies for building and deploying a Streamlit-based cryptocurrency dashboard. The first command installs essential Python libraries like Streamlit for the web app, BeautifulSoup4 for web scraping, Pandas for data manipulation, and Plotly for interactive visualizations. The second command installs LocalTunnel, which creates a public URL for accessing the Streamlit app from Colab.%%writefile app.pyimport streamlit as stimport requestsfrom bs4 import BeautifulSoupimport pandas as pdimport plotly.express as px# Function to scrape cryptocurrency pricesdef scrape_crypto_prices(): url = "https://coinmarketcap.com/" headers = {"User-Agent": "Mozilla/5.0"} response = requests.get(url, headers=headers) if response.status_code != 200: return pd.DataFrame(), "Error fetching data." soup = BeautifulSoup(response.text, "html.parser") rows = soup.select("tbody tr")[:10] # Get top 10 cryptocurrencies data = [] for row in rows: columns = row.find_all("td") name = columns[2].find("p").text # Crypto name symbol = columns[2].find("p", class_="coin-item-symbol").text # Symbol price = columns[3].text # Price change = columns[4].text # % Change market_cap = columns[6].text # Market Cap data.append([name, symbol, price, change, market_cap]) return pd.DataFrame(data, columns=["Name", "Symbol", "Price", "% Change", "Market Cap"]), None# Streamlit UIst.title(" Live Cryptocurrency Prices")data, error = scrape_crypto_prices()if error: st.error(error)else: st.dataframe(data) data["Price"] = data["Price"].replace({"$": "", ",": ""}, regex=True).astype(float) fig = px.bar(data, x="Symbol", y="Price", color="Name", title="Top 10 Cryptos by Price") st.plotly_chart(fig) fig_market_cap = px.pie(data, names="Name", values="Market Cap", title="Market Cap Distribution") st.plotly_chart(fig_market_cap)# Footerst.markdown(" Data scraped from CoinMarketCap. Updated in real-time.")Here, we define a Streamlit web application that scrapes real-time cryptocurrency prices from CoinMarketCap and displays them in an interactive dashboard. It uses BeautifulSoup4 to extract the top 10 cryptocurrencies, including their name, symbol, price, percentage change, and market capitalization. The scraped data is processed using Pandas and visualized with Plotly. The app presents a bar chart for price comparison and a pie chart for market capitalization distribution. The app displays an error message if an error occurs while fetching data. Finally, a footer note indicates that the data updates dynamically from CoinMarketCap.import subprocessimport time# Start Streamlit in the backgroundsubprocess.Popen(["streamlit", "run", "app.py", "--server.port=8501"])# Wait for Streamlit to starttime.sleep(5)# Start Cloudflare tunnel and expose the app!./cloudflared tunnel --url http://localhost:8501 --no-autoupdateFinally, the above code launches the Streamlit app in the background using subprocess.Popen and allows it to run on port 8501. A short delay (time.sleep(5)) ensures the app initializes properly before starting the Cloudflared tunnel, which creates a public URL to access the app from Google Colab without authentication or additional setup.App ViewDownload a CSV file of the dataIn conclusion, this tutorial provided a step-by-step guide to building and deploying a real-time cryptocurrency tracking app using Streamlit, BeautifulSoup, Pandas, and Plotly. We successfully scraped live crypto data from CoinMarketCap, displayed it in an interactive dashboard, and hosted it seamlessly using Cloudflared. Unlike traditional hosting methods, this approach ensures easy deployment without authentication hassles. Whether youre a beginner exploring web scraping and data visualization or a developer looking for a lightweight, accessible deployment method, this tutorial equips you with the tools to build and share interactive web apps efficiently.Here is the Colab Notebook and CSV File for the above project. Also,dont forget to follow us onTwitterand join ourTelegram ChannelandLinkedIn Group. Dont Forget to join our80k+ ML SubReddit. Asif RazzaqWebsite| + postsBioAsif Razzaq is the CEO of Marktechpost Media Inc.. As a visionary entrepreneur and engineer, Asif is committed to harnessing the potential of Artificial Intelligence for social good. His most recent endeavor is the launch of an Artificial Intelligence Media Platform, Marktechpost, which stands out for its in-depth coverage of machine learning and deep learning news that is both technically sound and easily understandable by a wide audience. The platform boasts of over 2 million monthly views, illustrating its popularity among audiences.Asif Razzaqhttps://www.marktechpost.com/author/6flvq/Qwen Releases QwQ-32B: A 32B Reasoning Model that Achieves Significantly Enhanced Performance in Downstream TaskAsif Razzaqhttps://www.marktechpost.com/author/6flvq/Researchers from FutureHouse and ScienceMachine Introduce BixBench: A Benchmark Designed to Evaluate AI Agents on Real-World Bioinformatics TaskAsif Razzaqhttps://www.marktechpost.com/author/6flvq/Step by Step Guide to Build an AI Research Assistant with Hugging Face SmolAgents: Automating Web Search and Article Summarization Using LLM-Powered Autonomous AgentsAsif Razzaqhttps://www.marktechpost.com/author/6flvq/Defog AI Open Sources Introspect: MIT-Licensed Deep-Research for Your Internal Data Recommended Open-Source AI Platform: IntellAgent is a An Open-Source Multi-Agent Framework to Evaluate Complex Conversational AI System' (Promoted)
0 Commentarii
·0 Distribuiri
·35 Views