This is my code: import yfinance as yf import gradio as gr Function to fetch stock data…
- User
This is my code: import yfinance as yf import gradio as gr
Function to fetch stock data
def get_stock_info(ticker): stock = yf.Ticker(ticker) info = stock.info if info: return (f"Stock Info for {ticker}:\n" f"Name: {info.get('longName')}\n" f"Sector: {info.get('sector')}\n" f"Market Cap: {info.get('marketCap')}\n" f"Previous Close: {info.get('previousClose')}\n" f"Open: {info.get('open')}\n" f"52 Week High: {info.get('fiftyTwoWeekHigh')}\n" f"52 Week Low: {info.get('fiftyTwoWeekLow')}") else: return f"No data found for ticker: {ticker}"
Create Gradio interface
iface = gr.Interface( fn=get_stock_info, inputs=gr.inputs.Textbox(lines=1, placeholder="Enter stock ticker..."), outputs="text", title="Stock Info Chatbot", description="Enter a stock ticker symbol to get information from Yahoo Finance." )
Launch the interface
iface.launch()
This is my output: AttributeError: module 'gradio' has no attribute 'inputs' -fix issue in the code
- Assistant
The error you're encountering is due to changes in the Gradio library's syntax. The
inputsattribute in Gradio has been updated. Instead of usinggr.inputs.Textbox, you should usegr.Textbox. Here’s how you can fix the code:import yfinance as yf import gradio as gr # Function to fetch stock data def get_stock_info(ticker): stock = yf.Ticker(ticker) info = stock.info if info: return (f"Stock Info for {ticker}:\n" f"Name: {info.get('longName')}\n" f"Sector: {info.get('sector')}\n" f"Market Cap: {info.get('marketCap')}\n" f"Previous Close: {info.get('previousClose')}\n" f"Open: {info.get('open')}\n" f"52 Week High: {info.get('fiftyTwoWeekHigh')}\n" f"52 Week Low: {info.get('fiftyTwoWeekLow')}") else: return f"No data found for ticker: {ticker}" # Create Gradio interface iface = gr.Interface( fn=get_stock_info, inputs=gr.Textbox(lines=1, placeholder="Enter stock ticker..."), outputs="text", title="Stock Info Chatbot", description="Enter a stock ticker symbol to get information from Yahoo Finance." ) # Launch the interface iface.launch()