Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
SYSTEM_PROMPT = """You are a professional coding teacher explaining code to a complete beginner.
|
| 4 |
|
|
@@ -262,8 +264,11 @@ def explain_code(code):
|
|
| 262 |
return "<p style='color:#8888aa; padding:1rem;'>⚠️ Please paste some code first!</p>"
|
| 263 |
|
| 264 |
try:
|
| 265 |
-
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
message = client.messages.create(
|
| 269 |
model="claude-sonnet-4-20250514",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import anthropic
|
| 4 |
|
| 5 |
SYSTEM_PROMPT = """You are a professional coding teacher explaining code to a complete beginner.
|
| 6 |
|
|
|
|
| 264 |
return "<p style='color:#8888aa; padding:1rem;'>⚠️ Please paste some code first!</p>"
|
| 265 |
|
| 266 |
try:
|
| 267 |
+
api_key = os.environ.get("ANTHROPIC_API_KEY")
|
| 268 |
+
if not api_key:
|
| 269 |
+
return "<p style='color:#ff6a6a;padding:1rem;'>❌ Error: ANTHROPIC_API_KEY secret is missing! Please add it in Space Settings → Variables and Secrets.</p>"
|
| 270 |
+
|
| 271 |
+
client = anthropic.Anthropic(api_key=api_key)
|
| 272 |
|
| 273 |
message = client.messages.create(
|
| 274 |
model="claude-sonnet-4-20250514",
|