It is so easy to create a simple chatbot interface for @ollama using @Gradio
code:python
import gradio as gr
import ollama
def format_history(query, history, system_prompt):
for h in history:
chat_history.append({"role": "user", "content": h0}) chat_history.append({"role": "assistant", "content": h1}) chat_history.append({"role": "user", "content": query})
return chat_history
def generate_response(query, history):
messages = format_history(query, history, "You are a helpful assistant")
response = ollama.chat(
model='llama3.2:3b',
messages=messages,
stream=True
)
message = ""
for chunk in response:
yield message
iface = gr.ChatInterface(
fn=generate_response,
title="Ollama Chat",
)
iface.launch()