CoolFace
Apppublic

ujwal00/zencode-AI-Code-assistant

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
app.py50 linesDownload Raw Back to root
1 2import requests3import json4import gradio as gr5 6# Ollama API endpoint7url = "http://localhost:11434/api/generate"8 9headers = {10    'Content-Type': 'application/json'11}12 13# For maintaining conversation history14history = []15 16def generate_response(prompt):17    history.append(f"User: {prompt}")18    final_prompt = "\n".join(history)19 20    # Request payload for Ollama21    data = {22        "model": "zencode",23        "prompt": final_prompt,24        "stream": False25    }26 27    try:28        response = requests.post(url, headers=headers, data=json.dumps(data))29 30        if response.status_code == 200:31            data = response.json()32            actual_response = data.get('response', 'No response found.')33 34            history.append(f"Zencode: {actual_response}")35            return actual_response36        else:37            return f"❌ Error: {response.status_code} - {response.text}"38 39    except Exception as e:40        return f"❌ Exception: {str(e)}"41 42# Gradio interface43interface = gr.Interface(44    fn=generate_response,45    inputs=gr.Textbox(lines=4, placeholder="Enter your prompt here...", label="Your Question"),46    outputs=gr.Textbox(label="Zencode's Response"),47    title="💡 Zencode - AI Coding Assistant"48)49 50interface.launch()