import google.generativeai as genai from pathlib import Path import gradio as gr import os genai.configure(api_key="AIzaSyByUqOoQh7ygr-YvRrCkEuWRqw__T1_1vk") model = genai.GenerativeModel(model_name="gemini-pro-vision") def read_image_data(file_path): image_path = Path(file_path) if not image_path.exists(): raise FileNotFoundError(f"Could not find image: {image_path}") return {"mime_type": "image/jpeg", "data": image_path.read_bytes()} def generate_gemini_response(prompt, image_path): image_data = read_image_data(image_path) response = model.generate_content([prompt, image_data]) return response.text input_prompt = """ As a seasoned market analyst with an uncanny ability to decipher the language of price charts, your expertise is crucial in navigating the turbulent seas of financial markets. You will be presented with static images of historical stock charts, where your keen eye will dissect the intricate dance of candlesticks, trendlines, and technical indicators. Armed with this visual intelligence, you will unlock the secrets hidden within these graphs, predicting the future trajectory of the depicted stock with remarkable accuracy. Analysis Guidelines: Pattern Recognition: Scan the chart to identify key candlestick patterns, trendlines, and technical indicators relevant to the timeframe and instrument displayed. Technical Analysis: Employ your comprehensive understanding of technical analysis methodologies to interpret the identified patterns and indicators, extracting insights into market sentiment, support and resistance levels, and potential upcoming price movements. Sentiment Prediction: Based on your technical analysis, forecast the probable future direction of the stock price. Should it tend towards bullish or bearish territory? Is a breakout or consolidation more likely? Confidence Level: Assess the strength and reliability of your prediction, providing a confidence level based on the clarity and confluence of the observed technical signals. Disclaimer: Remember, your insights are a powerful tool for informed decision-making, but not a guarantee of future performance. Always practice prudent risk management and seek professional financial advice before making any investment decisions. Your role is instrumental in empowering traders and investors with invaluable market intelligence. Proceed to analyze the provided chart, unraveling its secrets with the precision and confidence of a master chart reader. And provide the output in English """ # Function to process uploaded files and generate a response def process_uploaded_files(files): file_path = files[0].name if files else None response = generate_gemini_response(input_prompt, file_path) if file_path else None return file_path, response # Gradio interface with gr.Blocks() as demo: file_output = gr.Textbox() image_output = gr.Image() combined_output = [image_output, file_output] upload_button = gr.UploadButton( "Click to Upload Chart Screenshot", file_types=["image"], file_count="multiple", ) upload_button.upload(process_uploaded_files, upload_button, combined_output) demo.launch(debug=True)