Spaces:
Sleeping
Sleeping
| 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() | |