Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ def load_openai_key():
|
|
| 13 |
"""Load OpenAI API key from HuggingFace secrets"""
|
| 14 |
try:
|
| 15 |
# Try to get from HuggingFace secrets via environment variable
|
| 16 |
-
api_key = os.getenv('
|
| 17 |
|
| 18 |
if not api_key:
|
| 19 |
st.error("OpenAI API key not found in HuggingFace secrets. Please ensure the secret is set as OPENAI_API_KEY_HF in your HuggingFace space.")
|
|
@@ -68,9 +68,10 @@ def detect_chart_type(client, image_data):
|
|
| 68 |
|
| 69 |
def create_prompt_template(patterns, indicators):
|
| 70 |
"""Creates a structured prompt for the LLM based on the chart and analysis needs"""
|
| 71 |
-
prompt = """You are an expert financial analyst. Please analyze this
|
| 72 |
|
| 73 |
1. VISUAL ANALYSIS
|
|
|
|
| 74 |
- Identify and describe the main trend
|
| 75 |
- Note key price levels visible in the chart
|
| 76 |
- Describe any significant patterns: {patterns}
|
|
@@ -99,11 +100,11 @@ def create_prompt_template(patterns, indicators):
|
|
| 99 |
Provide a 2-3 sentence summary in simple terms for novice traders.
|
| 100 |
|
| 101 |
IMPORTANT: Clearly mark this as AI-generated analysis for informational purposes only.
|
| 102 |
-
"""
|
|
|
|
| 103 |
patterns=', '.join(patterns) if patterns else 'all visible patterns',
|
| 104 |
indicators=', '.join(indicators) if indicators else 'visible indicators'
|
| 105 |
)
|
| 106 |
-
return prompt
|
| 107 |
|
| 108 |
def analyze_chart_with_openai(client, image_data, prompt, chart_type=None):
|
| 109 |
"""Analyze chart using OpenAI's GPT-4 model"""
|
|
@@ -232,7 +233,7 @@ def main():
|
|
| 232 |
|
| 233 |
# Display uploaded image
|
| 234 |
if uploaded_file is not None:
|
| 235 |
-
st.image(uploaded_file, caption="Uploaded Chart",
|
| 236 |
|
| 237 |
if st.button("Analyze"):
|
| 238 |
if upload_option == "Ask Question" and user_question:
|
|
|
|
| 13 |
"""Load OpenAI API key from HuggingFace secrets"""
|
| 14 |
try:
|
| 15 |
# Try to get from HuggingFace secrets via environment variable
|
| 16 |
+
api_key = os.getenv('OPENAI_API_KEY_HF')
|
| 17 |
|
| 18 |
if not api_key:
|
| 19 |
st.error("OpenAI API key not found in HuggingFace secrets. Please ensure the secret is set as OPENAI_API_KEY_HF in your HuggingFace space.")
|
|
|
|
| 68 |
|
| 69 |
def create_prompt_template(patterns, indicators):
|
| 70 |
"""Creates a structured prompt for the LLM based on the chart and analysis needs"""
|
| 71 |
+
prompt = """You are an expert financial analyst. Please analyze this financial chart (chart type will be detected automatically) and provide insights in the following structured format:
|
| 72 |
|
| 73 |
1. VISUAL ANALYSIS
|
| 74 |
+
- First identify the type of chart (candlestick, line, OHLC, area, etc.)
|
| 75 |
- Identify and describe the main trend
|
| 76 |
- Note key price levels visible in the chart
|
| 77 |
- Describe any significant patterns: {patterns}
|
|
|
|
| 100 |
Provide a 2-3 sentence summary in simple terms for novice traders.
|
| 101 |
|
| 102 |
IMPORTANT: Clearly mark this as AI-generated analysis for informational purposes only.
|
| 103 |
+
"""
|
| 104 |
+
return prompt.format(
|
| 105 |
patterns=', '.join(patterns) if patterns else 'all visible patterns',
|
| 106 |
indicators=', '.join(indicators) if indicators else 'visible indicators'
|
| 107 |
)
|
|
|
|
| 108 |
|
| 109 |
def analyze_chart_with_openai(client, image_data, prompt, chart_type=None):
|
| 110 |
"""Analyze chart using OpenAI's GPT-4 model"""
|
|
|
|
| 233 |
|
| 234 |
# Display uploaded image
|
| 235 |
if uploaded_file is not None:
|
| 236 |
+
st.image(uploaded_file, caption="Uploaded Chart", use_container_width=True)
|
| 237 |
|
| 238 |
if st.button("Analyze"):
|
| 239 |
if upload_option == "Ask Question" and user_question:
|