Kr08/Stock_Forecasting
0
1from datetime import datetime2import gradio as gr3from data_fetcher import get_stocks_from_index4from stock_analysis import get_stock_graph_and_info5 6def validate_date(date_string):7 try:8 return datetime.strptime(date_string, "%Y-%m-%d").date()9 except ValueError:10 return None11 12def update_stock_options(index):13 stocks = get_stocks_from_index(index)14 return gr.Dropdown(choices=stocks)15 16def process_inputs(*args):17 idx, stock, interval, graph_type, forecast_method, start_date, end_date = args18 19 start = validate_date(start_date)20 end = validate_date(end_date)21 22 if start is None or end is None:23 return gr.Textbox(value="Invalid date format. Please use YYYY-MM-DD."), None24 25 if start > end:26 return gr.Textbox(value="Start date must be before end date."), None27 28 try:29 return get_stock_graph_and_info(idx, stock, interval, graph_type, forecast_method, start, end)30 except Exception as e:31 error_message = f"An error occurred: {str(e)}"32 return gr.Textbox(value=error_message), None