Spaces:
Runtime error
Runtime error
Update services/claude_service.py
Browse files- services/claude_service.py +46 -1
services/claude_service.py
CHANGED
|
@@ -84,7 +84,52 @@ class ClaudeService:
|
|
| 84 |
|
| 85 |
result = self.analyze_image(image_data, prompt)
|
| 86 |
return result.strip() if result else "Other"
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
def get_educational_content(self, concept):
|
| 89 |
"""Get educational content about trading concepts"""
|
| 90 |
try:
|
|
|
|
| 84 |
|
| 85 |
result = self.analyze_image(image_data, prompt)
|
| 86 |
return result.strip() if result else "Other"
|
| 87 |
+
|
| 88 |
+
def generate_diagram(self, prompt):
|
| 89 |
+
"""Generate an SVG diagram using Claude"""
|
| 90 |
+
try:
|
| 91 |
+
message = self.client.messages.create(
|
| 92 |
+
model=self.model,
|
| 93 |
+
max_tokens=1000,
|
| 94 |
+
messages=[{
|
| 95 |
+
"role": "user",
|
| 96 |
+
"content": f"""Please create an SVG diagram based on this request: {prompt}
|
| 97 |
+
Make the diagram clean, professional, and educational.
|
| 98 |
+
Use standard SVG elements and ensure the viewBox is properly set.
|
| 99 |
+
Keep colors accessible and include clear labels."""
|
| 100 |
+
}]
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
response = message.content[0].text
|
| 104 |
+
|
| 105 |
+
# Extract SVG content if present
|
| 106 |
+
if '<svg' in response and '</svg>' in response:
|
| 107 |
+
svg_start = response.find('<svg')
|
| 108 |
+
svg_end = response.find('</svg>') + 6
|
| 109 |
+
return response[svg_start:svg_end]
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
except Exception as e:
|
| 113 |
+
st.error(f"Error generating diagram: {str(e)}")
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
def generate_educational_content(self, prompt):
|
| 117 |
+
"""Generate educational content using Claude"""
|
| 118 |
+
try:
|
| 119 |
+
message = self.client.messages.create(
|
| 120 |
+
model=self.model,
|
| 121 |
+
max_tokens=1500,
|
| 122 |
+
messages=[{
|
| 123 |
+
"role": "user",
|
| 124 |
+
"content": prompt
|
| 125 |
+
}]
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
return message.content[0].text
|
| 129 |
+
|
| 130 |
+
except Exception as e:
|
| 131 |
+
st.error(f"Error generating educational content: {str(e)}")
|
| 132 |
+
return None
|
| 133 |
def get_educational_content(self, concept):
|
| 134 |
"""Get educational content about trading concepts"""
|
| 135 |
try:
|