sitammeur commited on
Commit
beb3668
·
verified ·
1 Parent(s): 32663ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -11
app.py CHANGED
@@ -2,23 +2,27 @@
2
  import warnings
3
  warnings.filterwarnings("ignore")
4
 
 
5
  import json
6
  import subprocess
7
  import sys
 
8
  from llama_cpp import Llama
9
  from llama_cpp_agent import LlamaCppAgent
10
  from llama_cpp_agent import MessagesFormatterType
11
  from llama_cpp_agent.providers import LlamaCppPythonProvider
12
  from llama_cpp_agent.chat_history import BasicChatHistory
13
  from llama_cpp_agent.chat_history.messages import Roles
14
- import gradio as gr
15
  from huggingface_hub import hf_hub_download
16
- from typing import List, Tuple
17
  from logger import logging
18
  from exception import CustomExceptionHandling
19
 
20
 
21
  # Download gguf model files
 
 
 
22
  hf_hub_download(
23
  repo_id="bartowski/Dolphin3.0-Llama3.2-1B-GGUF",
24
  filename="Dolphin3.0-Llama3.2-1B-Q6_K.gguf",
@@ -42,13 +46,13 @@ llm_model = None
42
  def respond(
43
  message: str,
44
  history: List[Tuple[str, str]],
45
- model: str,
46
- system_message: str,
47
- max_tokens: int,
48
- temperature: float,
49
- top_p: float,
50
- top_k: int,
51
- repeat_penalty: float,
52
  ):
53
  """
54
  Respond to a message using the Dolphin-3 model via Llama.cpp.
@@ -72,8 +76,18 @@ def respond(
72
  global llm
73
  global llm_model
74
 
 
 
 
 
75
  # Load the model
76
  if llm is None or llm_model != model:
 
 
 
 
 
 
77
  llm = Llama(
78
  model_path=f"models/{model}",
79
  flash_attn=False,
@@ -205,11 +219,18 @@ demo = gr.ChatInterface(
205
  stop_btn="Stop",
206
  title=title,
207
  description=description,
208
- chatbot=gr.Chatbot(scale=1, show_copy_button=True),
209
  flagging_mode="never",
 
 
210
  )
211
 
212
 
213
  # Launch the chat interface
214
  if __name__ == "__main__":
215
- demo.launch(debug=False)
 
 
 
 
 
 
2
  import warnings
3
  warnings.filterwarnings("ignore")
4
 
5
+ import os
6
  import json
7
  import subprocess
8
  import sys
9
+ from typing import List, Tuple
10
  from llama_cpp import Llama
11
  from llama_cpp_agent import LlamaCppAgent
12
  from llama_cpp_agent import MessagesFormatterType
13
  from llama_cpp_agent.providers import LlamaCppPythonProvider
14
  from llama_cpp_agent.chat_history import BasicChatHistory
15
  from llama_cpp_agent.chat_history.messages import Roles
 
16
  from huggingface_hub import hf_hub_download
17
+ import gradio as gr
18
  from logger import logging
19
  from exception import CustomExceptionHandling
20
 
21
 
22
  # Download gguf model files
23
+ if not os.path.exists("./models"):
24
+ os.makedirs("./models")
25
+
26
  hf_hub_download(
27
  repo_id="bartowski/Dolphin3.0-Llama3.2-1B-GGUF",
28
  filename="Dolphin3.0-Llama3.2-1B-Q6_K.gguf",
 
46
  def respond(
47
  message: str,
48
  history: List[Tuple[str, str]],
49
+ model: str = "Dolphin3.0-Qwen2.5-0.5B-Q6_K.gguf", # Set default model
50
+ system_message: str = "You are a helpful assistant.",
51
+ max_tokens: int = 1024,
52
+ temperature: float = 0.7,
53
+ top_p: float = 0.95,
54
+ top_k: int = 40,
55
+ repeat_penalty: float = 1.1,
56
  ):
57
  """
58
  Respond to a message using the Dolphin-3 model via Llama.cpp.
 
76
  global llm
77
  global llm_model
78
 
79
+ # Ensure model is not None
80
+ if model is None:
81
+ model = "Dolphin3.0-Qwen2.5-0.5B-Q6_K.gguf"
82
+
83
  # Load the model
84
  if llm is None or llm_model != model:
85
+ # Check if model file exists
86
+ model_path = f"models/{model}"
87
+ if not os.path.exists(model_path):
88
+ yield f"Error: Model file not found at {model_path}. Please check your model path."
89
+ return
90
+
91
  llm = Llama(
92
  model_path=f"models/{model}",
93
  flash_attn=False,
 
219
  stop_btn="Stop",
220
  title=title,
221
  description=description,
222
+ chatbot=gr.Chatbot(scale=1, show_copy_button=True, resizable=True),
223
  flagging_mode="never",
224
+ editable=True,
225
+ cache_examples=False,
226
  )
227
 
228
 
229
  # Launch the chat interface
230
  if __name__ == "__main__":
231
+ demo.launch(
232
+ share=False,
233
+ server_name="0.0.0.0",
234
+ server_port=7860,
235
+ show_api=False,
236
+ )