File size: 1,462 Bytes
cbcbc7e
 
f7d5472
 
 
91abf63
f7d5472
 
91abf63
f7d5472
91abf63
 
 
 
f7d5472
 
91abf63
f7d5472
 
 
 
7ac8bf6
 
 
f7d5472
7ac8bf6
 
 
f7d5472
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 subprocess
import gradio as gr
import ollama

# Ensure ollama is installed via pip
def install_ollama():
    try:
        import ollama
        print("βœ… Ollama is already installed.")
    except ImportError:
        print("πŸš€ Installing Ollama via pip...")
        subprocess.run(["pip", "install", "ollama"], check=True)
        import ollama  # Re-import after installation
        print("βœ… Ollama installed successfully!")

# Ensure model is downloaded
MODEL_NAME = "deepseek-llm-7b"
MODEL_PATH = f"models/{MODEL_NAME}"

def download_model():
    models = ollama.list()
    if any(m["name"] == MODEL_NAME for m in models["models"]):
        print(f"βœ… Model '{MODEL_NAME}' is already available.")
    else:
        print(f"πŸš€ Downloading model: {MODEL_NAME} ...")
        ollama.pull(MODEL_NAME)
        print(f"βœ… Model '{MODEL_NAME}' downloaded successfully.")

# Generate AI response using Ollama
def chat_response(user_input):
    response = ollama.chat(model=MODEL_NAME, messages=[{"role": "user", "content": user_input}])
    return response['message']['content']

# Run setup
install_ollama()
download_model()

# Create Gradio Interface
iface = gr.Interface(
    fn=chat_response,
    inputs="text",
    outputs="text",
    title="DeepSeek ChatBot (Ollama)",
    description="Chat with DeepSeek LLM 7B using Ollama."
)

# Launch Gradio App
if __name__ == "__main__":
    iface.launch(server_name="0.0.0.0", server_port=7860)