Spaces:
Build error
Build error
Update app.py
Browse files123456785910711121391415161112171819202114151622232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576771819207879import streamlit as stfrom transformers import pipelinefrom PIL import Imageimport yfinance as yfimport matplotlib.pyplot as pltimport io
# Load the image classification pipelinepipeline = pipeline(task="image-classification", model="julien-c/bullish-or-bearish")classifier = pipeline(task="image-classification", model="julien-c/bullish-or-bearish")
st.title("Hot Dog? Or Not?")# Set up the Streamlit app titlest.title("Stock Trend Analyzer: Bullish or Bearish? 📈📉")
file_name = st.file_uploader("Upload a hot dog candidate image")# Input for stock tickerticker = st.text_input("Enter a stock ticker (e.g., AAPL, GOOGL):", "AAPL")
if file_name is not None: col1, col2 = st.columns(2)# Date range selectioncol1, col2 = st.columns(2)start_date = col1.date_input("Start date")end_date = col2.date_input("End date")
image = Image.open(file_name) col1.image(image, use_column_width=True) predictions = pipeline(image)if st.button("Analyze"): # Fetch stock data stock_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 data plt.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 buffer buf = io.BytesIO() plt.savefig(buf, format='png') buf.seek(0) # Convert the buffer to an image image = Image.open(buf) # Display the stock graph st.image(image, caption=f"{ticker} Stock Price", use_column_width=True) # Classify the image with st.spinner("Analyzing the trend..."): predictions = classifier(image) # Display the predictions st.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 representation color = "green" if sentiment == "Bullish" else "red" st.progress(confidence / 100, text=f"{sentiment} Confidence") # Additional analysis based on the stock data price_change = stock_data['Close'].iloc[-1] - stock_data['Close'].iloc[0] percent_change = (price_change / stock_data['Close'].iloc[0]) * 100 st.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.")
col2.header("Probabilities") for p in predictions: col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")else: st.info("Enter a stock ticker and select a date range to analyze the trend.")app.py+70-11