shamamanaeem03 commited on
Commit
271a1c7
·
verified ·
1 Parent(s): e57a2ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -1,6 +1,6 @@
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,20 +264,22 @@ def explain_code(code):
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",
275
  max_tokens=2000,
276
- system=SYSTEM_PROMPT,
277
- messages=[{"role": "user", "content": f"Explain this code:\n\n{code}"}]
 
 
278
  )
279
-
280
- result = message.content[0].text
281
 
282
  # Wrap in styled container
283
  return f"""
@@ -342,7 +344,7 @@ with gr.Blocks(css=CSS, title="CodeLens — AI Code Explainer") as demo:
342
 
343
  gr.HTML("""
344
  <div style="text-align:center; padding:1.5rem 0 0.5rem; color:#8888aa; font-size:0.82rem; font-family:'DM Sans',sans-serif;">
345
- Built with ❤️ using Claude AI · CodeLens for Beginners
346
  </div>
347
  """)
348
 
 
1
  import gradio as gr
2
  import os
3
+ from groq import Groq
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("GROQ_API_KEY")
268
  if not api_key:
269
+ return "<p style='color:#ff6a6a;padding:1rem;'>❌ Error: GROQ_API_KEY secret is missing! Go to Space Settings → Variables and Secrets → Add GROQ_API_KEY</p>"
270
 
271
+ client = Groq(api_key=api_key)
272
+
273
+ response = client.chat.completions.create(
274
+ model="llama3-70b-8192",
275
  max_tokens=2000,
276
+ messages=[
277
+ {"role": "system", "content": SYSTEM_PROMPT},
278
+ {"role": "user", "content": f"Explain this code:\n\n{code}"}
279
+ ]
280
  )
281
+
282
+ result = response.choices[0].message.content
283
 
284
  # Wrap in styled container
285
  return f"""
 
344
 
345
  gr.HTML("""
346
  <div style="text-align:center; padding:1.5rem 0 0.5rem; color:#8888aa; font-size:0.82rem; font-family:'DM Sans',sans-serif;">
347
+ Built with ❤️ using Groq AI · CodeLens for Beginners
348
  </div>
349
  """)
350