Update app.py
Browse files
app.py
CHANGED
|
@@ -1,2 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import ollama # Ensure ollama is available in your Space
|
| 3 |
+
|
| 4 |
+
# Define chat function
|
| 5 |
+
def chat_with_model(message, history):
|
| 6 |
+
try:
|
| 7 |
+
response = ollama.chat(
|
| 8 |
+
model="mistral-small",
|
| 9 |
+
messages=[{"role": "user", "content": message}]
|
| 10 |
+
)
|
| 11 |
+
return response['message']['content']
|
| 12 |
+
except Exception as e:
|
| 13 |
+
return f"Error: {str(e)}"
|
| 14 |
+
|
| 15 |
+
# Define Gradio Chat Interface
|
| 16 |
+
chatbot = gr.ChatInterface(
|
| 17 |
+
chat_with_model,
|
| 18 |
+
title="Mistral AI Chatbot",
|
| 19 |
+
description="Chat with Mistral-Small using Ollama on Hugging Face Spaces.",
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Launch the Gradio app
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
chatbot.launch()
|