Ayyyesha's picture
Update app.py
9c5dc92 verified
Raw
History Blame Contribute Delete
1.59 kB
import os
import gradio as gr
from groq import Groq
# πŸ” Get API Key from Hugging Face secret
GROQ_API_KEY = os.environ.get("AI_Code_Assistant") # βœ… Corrected secret name
# 🧠 Groq Debug Function
def debug_with_groq(code, issue, language):
try:
client = Groq(api_key=GROQ_API_KEY)
prompt = f"""You are an expert debugger for {language} code.
Code:
{code}
Problem:
{issue}
Explain the error clearly and provide the corrected {language} code."""
response = client.chat.completions.create(
model="llama3-70b-8192",
messages=[{"role": "user", "content": prompt}],
temperature=0.3,
max_tokens=800
)
return response.choices[0].message.content
except Exception as e:
return f"❌ Error: {str(e)}"
# 🎨 Gradio UI
with gr.Blocks() as app:
gr.Markdown("## 🧠 SoulSync DebugMate")
gr.Markdown("Paste your code, select language, and describe the issue to get a fix.")
code_input = gr.Code(label="πŸ”§ Your Buggy Code", language="python")
language_selector = gr.Dropdown(
choices=["Python", "JavaScript", "C++", "Java", "HTML", "C#", "PHP", "Go"],
label="πŸ’¬ Select Programming Language",
value="Python"
)
issue_input = gr.Textbox(label="🐞 Describe the Issue", placeholder="e.g., function throws an error")
output = gr.Textbox(label="βœ… AI Response", lines=10)
run_btn = gr.Button("πŸ›  Debug Now")
run_btn.click(fn=debug_with_groq, inputs=[code_input, issue_input, language_selector], outputs=output)
app.launch()