File size: 662 Bytes
3e2c343 70fc16f | 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 | import gradio as gr
import ollama # Ensure ollama is available in your Space
# Define chat function
def chat_with_model(message, history):
try:
response = ollama.chat(
model="mistral-small",
messages=[{"role": "user", "content": message}]
)
return response['message']['content']
except Exception as e:
return f"Error: {str(e)}"
# Define Gradio Chat Interface
chatbot = gr.ChatInterface(
chat_with_model,
title="Mistral AI Chatbot",
description="Chat with Mistral-Small using Ollama on Hugging Face Spaces.",
)
# Launch the Gradio app
if __name__ == "__main__":
chatbot.launch()
|