Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,34 @@
|
|
| 1 |
-
import
|
| 2 |
from ctransformers import AutoModelForCausalLM
|
| 3 |
|
| 4 |
# Define the model repository and file
|
| 5 |
model_repo = "TheBloke/OpenHermes-2-Mistral-7B-GGUF"
|
| 6 |
model_file = "openhermes-2-mistral-7b.Q4_K_M.gguf"
|
| 7 |
|
| 8 |
-
# Download the model
|
| 9 |
print(f"Downloading {model_file} from {model_repo}...")
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
model_repo,
|
| 12 |
model_file=model_file,
|
| 13 |
model_type="mistral",
|
| 14 |
-
# Uncomment
|
| 15 |
-
# gpu_layers=50
|
| 16 |
)
|
| 17 |
print("Model downloaded and loaded successfully.")
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
prompt
|
| 21 |
-
response = model(prompt)
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from ctransformers import AutoModelForCausalLM
|
| 3 |
|
| 4 |
# Define the model repository and file
|
| 5 |
model_repo = "TheBloke/OpenHermes-2-Mistral-7B-GGUF"
|
| 6 |
model_file = "openhermes-2-mistral-7b.Q4_K_M.gguf"
|
| 7 |
|
| 8 |
+
# Download and load the model
|
| 9 |
print(f"Downloading {model_file} from {model_repo}...")
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
model_repo,
|
| 12 |
model_file=model_file,
|
| 13 |
model_type="mistral",
|
| 14 |
+
# Uncomment if GPU is available
|
| 15 |
+
# gpu_layers=50
|
| 16 |
)
|
| 17 |
print("Model downloaded and loaded successfully.")
|
| 18 |
|
| 19 |
+
# Define the function to interact with the model
|
| 20 |
+
def chat_with_model(prompt):
|
| 21 |
+
response = model(prompt)
|
| 22 |
+
return response
|
| 23 |
+
|
| 24 |
+
# Create a Gradio interface
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=chat_with_model,
|
| 27 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask something..."),
|
| 28 |
+
outputs="text",
|
| 29 |
+
title="Mistral 7B Chatbot",
|
| 30 |
+
description="Interact with Mistral-7B using GGUF & ctransformers.",
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Launch the Gradio app
|
| 34 |
+
iface.launch()
|