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()