File size: 1,593 Bytes
3f1f2c0
0665237
3f1f2c0
 
9684f3d
9c5dc92
3f1f2c0
9684f3d
3f1f2c0
 
9c5dc92
3f1f2c0
 
 
33677c6
3f1f2c0
 
 
 
 
 
 
 
 
 
 
c3a519d
3f1f2c0
 
 
 
33677c6
3f1f2c0
 
 
 
 
 
 
 
 
 
 
 
 
 
0665237
3f1f2c0
0665237
3f1f2c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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()