ntaexams commited on
Commit
9c70ca8
·
verified ·
1 Parent(s): 872193e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -1,22 +1,34 @@
1
- import os
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 using ctransformers
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 the following line if you have a CUDA-capable GPU
15
- # gpu_layers=50
16
  )
17
  print("Model downloaded and loaded successfully.")
18
 
19
- # Test the model with a simple prompt
20
- prompt = "AI is going to"
21
- response = model(prompt)
22
- print(f"Prompt: {prompt}\nResponse: {response}")
 
 
 
 
 
 
 
 
 
 
 
 
 
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()