File size: 1,245 Bytes
126833d
 
 
6d0d01c
 
126833d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d0d01c
126833d
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

import requests
import json
import gradio as gr

# Ollama API endpoint
url = "http://localhost:11434/api/generate"

headers = {
    'Content-Type': 'application/json'
}

# For maintaining conversation history
history = []

def generate_response(prompt):
    history.append(f"User: {prompt}")
    final_prompt = "\n".join(history)

    # Request payload for Ollama
    data = {
        "model": "zencode",
        "prompt": final_prompt,
        "stream": False
    }

    try:
        response = requests.post(url, headers=headers, data=json.dumps(data))

        if response.status_code == 200:
            data = response.json()
            actual_response = data.get('response', 'No response found.')

            history.append(f"Zencode: {actual_response}")
            return actual_response
        else:
            return f"❌ Error: {response.status_code} - {response.text}"

    except Exception as e:
        return f"❌ Exception: {str(e)}"

# Gradio interface
interface = gr.Interface(
    fn=generate_response,
    inputs=gr.Textbox(lines=4, placeholder="Enter your prompt here...", label="Your Question"),
    outputs=gr.Textbox(label="Zencode's Response"),
    title="💡 Zencode - AI Coding Assistant"
)

interface.launch()