Hjgugugjhuhjggg commited on
Commit
5a6f7e7
·
verified ·
1 Parent(s): 678a7bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -18
app.py CHANGED
@@ -14,19 +14,7 @@ from pydantic import BaseModel
14
  load_dotenv()
15
  HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
16
 
17
- global_data = {
18
- 'models': {},
19
- 'tokens': {
20
- 'eos': 'eos_token',
21
- 'pad': 'pad_token',
22
- 'padding': 'padding_token',
23
- 'unk': 'unk_token',
24
- 'bos': 'bos_token',
25
- 'sep': 'sep_token',
26
- 'cls': 'cls_token',
27
- 'mask': 'mask_token'
28
- }
29
- }
30
 
31
  model_configs = [
32
  {"repo_id": "Hjgugugjhuhjggg/mergekit-ties-tzamfyy-Q2_K-GGUF", "filename": "mergekit-ties-tzamfyy-q2_k.gguf", "name": "my_model"}
@@ -44,11 +32,13 @@ def load_model(model_config):
44
  return model
45
  except Exception as e:
46
  print(f"Error loading model {model_name}: {e}")
47
- models[model_name] = None
48
  return None
49
 
50
  for config in model_configs:
51
- load_model(config)
 
 
 
52
 
53
 
54
  class ChatRequest(BaseModel):
@@ -71,7 +61,7 @@ def remove_duplicates(text):
71
  def generate_model_response(model, inputs):
72
  try:
73
  if model is None:
74
- return ""
75
  response = model(inputs)
76
  return remove_duplicates(response['choices'][0]['text'])
77
  except Exception as e:
@@ -112,7 +102,7 @@ async def process_message(message, history):
112
  response = requests.post(f"http://localhost:{port}/generate", json={"message": message}).json()
113
  formatted_response = response["response"]
114
  history.append((message, formatted_response))
115
- return history, ""
116
  except requests.exceptions.RequestException as e:
117
  return history, f"Error communicating with the backend: {e}"
118
 
@@ -122,7 +112,7 @@ iface = gr.Interface(
122
  gr.Textbox(lines=2, placeholder="Enter your message here..."),
123
  gr.State([])
124
  ],
125
- outputs=[gr.Chatbot(), gr.Textbox(visible=False)],
126
  title="Multi-Model LLM API",
127
  description="Enter a message and get responses from multiple LLMs.",
128
  )
 
14
  load_dotenv()
15
  HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
16
 
17
+ global_data = {'models': {}, 'tokens': {'eos': 'eos_token', 'pad': 'pad_token', 'padding': 'padding_token', 'unk': 'unk_token', 'bos': 'bos_token', 'sep': 'sep_token', 'cls': 'cls_token', 'mask': 'mask_token'}}
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  model_configs = [
20
  {"repo_id": "Hjgugugjhuhjggg/mergekit-ties-tzamfyy-Q2_K-GGUF", "filename": "mergekit-ties-tzamfyy-q2_k.gguf", "name": "my_model"}
 
32
  return model
33
  except Exception as e:
34
  print(f"Error loading model {model_name}: {e}")
 
35
  return None
36
 
37
  for config in model_configs:
38
+ model = load_model(config)
39
+ if model is None:
40
+ print(f"Failed to load model {config['name']}. Exiting.")
41
+ exit(1)
42
 
43
 
44
  class ChatRequest(BaseModel):
 
61
  def generate_model_response(model, inputs):
62
  try:
63
  if model is None:
64
+ return "Model loading failed."
65
  response = model(inputs)
66
  return remove_duplicates(response['choices'][0]['text'])
67
  except Exception as e:
 
102
  response = requests.post(f"http://localhost:{port}/generate", json={"message": message}).json()
103
  formatted_response = response["response"]
104
  history.append((message, formatted_response))
105
+ return history, history
106
  except requests.exceptions.RequestException as e:
107
  return history, f"Error communicating with the backend: {e}"
108
 
 
112
  gr.Textbox(lines=2, placeholder="Enter your message here..."),
113
  gr.State([])
114
  ],
115
+ outputs=[gr.Chatbot(), gr.State([])],
116
  title="Multi-Model LLM API",
117
  description="Enter a message and get responses from multiple LLMs.",
118
  )