Spaces:
Build error
Build error
Update app.py
Browse files1234567891011121314151617181920import streamlit as stfrom transformers import pipelinefrom PIL import Imagepipeline = pipeline(task="image-classification", model="julien-c/bullish-or-bearish")st.title("Hot Dog? Or Not?")file_name = st.file_uploader("Upload a hot dog candidate image")if file_name is not None:col1, col2 = st.columns(2)image = Image.open(file_name)col1.image(image, use_column_width=True)predictions = pipeline(image)col2.header("Probabilities")for p in predictions:col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import streamlit as stfrom transformers import pipelinefrom PIL import Imageimport yfinance as yfimport matplotlib.pyplot as pltimport io# Load the image classification pipelineclassifier = pipeline(task="image-classification", model="julien-c/bullish-or-bearish")# Set up the Streamlit app titlest.title("Stock Trend Analyzer: Bullish or Bearish? 📈📉")# Input for stock tickerticker = st.text_input("Enter a stock ticker (e.g., AAPL, GOOGL):", "AAPL")# Date range selectioncol1, col2 = st.columns(2)start_date = col1.date_input("Start date")end_date = col2.date_input("End date")if st.button("Analyze"):# Fetch stock datastock_data = yf.download(ticker, start=start_date, end=end_date)if stock_data.empty:st.error("No data available for the selected stock and date range.")else:# Create a plot of the stock dataplt.figure(figsize=(10, 6))plt.plot(stock_data.index, stock_data['Close'])plt.title(f"{ticker} Stock Price")plt.xlabel("Date")plt.ylabel("Price")plt.grid(True)# Save the plot to a bufferbuf = io.BytesIO()plt.savefig(buf, format='png')buf.seek(0)# Convert the buffer to an imageimage = Image.open(buf)# Display the stock graphst.image(image, caption=f"{ticker} Stock Price", use_column_width=True)# Classify the imagewith st.spinner("Analyzing the trend..."):predictions = classifier(image)# Display the predictionsst.header("Trend Analysis")for p in predictions:sentiment = p['label'].split('_')[0].capitalize()confidence = round(p['score'] * 100, 1)st.subheader(f"{sentiment}: {confidence}%")# Add color-coded bars for visual representationcolor = "green" if sentiment == "Bullish" else "red"st.progress(confidence / 100, text=f"{sentiment} Confidence")# Additional analysis based on the stock dataprice_change = stock_data['Close'].iloc[-1] - stock_data['Close'].iloc[0]percent_change = (price_change / stock_data['Close'].iloc[0]) * 100st.subheader("Price Analysis")st.write(f"Price change: ${price_change:.2f}")st.write(f"Percent change: {percent_change:.2f}%")if percent_change > 0:st.success(f"The stock price increased by {percent_change:.2f}% over the selected period.")elif percent_change < 0:st.error(f"The stock price decreased by {abs(percent_change):.2f}% over the selected period.")else:st.info("The stock price remained unchanged over the selected period.")else:st.info("Enter a stock ticker and select a date range to analyze the trend.")
app.py+70-11