|
|
| |
| |
| |
| import os |
| os.environ["GROQ_API_KEY"] = "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" |
|
|
| |
| |
| |
| import gradio as gr |
| from groq import Groq |
|
|
| |
| |
| |
| API_KEY = os.environ.get("GROQ_API_KEY") |
|
|
| |
| |
| |
| def codegenie_chat(user_prompt): |
| if not API_KEY: |
| return "β GROQ_API_KEY not found." |
|
|
| if not user_prompt or user_prompt.strip() == "": |
| return "β Please enter a programming request." |
|
|
| try: |
| client = Groq(api_key=API_KEY) |
|
|
| system_prompt = """ |
| You are CodeGenie β an AI Programming Assistant. |
| |
| Capabilities: |
| - Automatic programming language detection |
| - Multi-language code generation |
| - Basic programs and DSA support |
| - Simple code explanation |
| - Clean and readable output |
| """ |
|
|
| response = client.chat.completions.create( |
| model="llama-3.3-70b-versatile", |
| messages=[ |
| {"role": "system", "content": system_prompt}, |
| {"role": "user", "content": user_prompt} |
| ], |
| temperature=0.3, |
| ) |
|
|
| return response.choices[0].message.content |
|
|
| except Exception as e: |
| return f"β Error:\n{str(e)}" |
|
|
| |
| |
| |
| with gr.Blocks(theme=gr.themes.Soft()) as app: |
| gr.Markdown(""" |
| # π€ CodeGenie β AI Programming Assistant |
| *Code β’ DSA β’ Explanation β’ Multi-language* |
| Google Colab Version π |
| """) |
|
|
| user_input = gr.Textbox( |
| label="π» Enter your programming request", |
| placeholder="e.g. Write Python code for stack using array with explanation", |
| lines=4 |
| ) |
|
|
| generate_btn = gr.Button("π Generate Code") |
|
|
| output_box = gr.Markdown() |
|
|
| generate_btn.click( |
| fn=codegenie_chat, |
| inputs=user_input, |
| outputs=output_box |
| ) |
|
|
| app.launch(share=True) |