baconnier commited on
Commit
2ef2957
1 Parent(s): fa7f1bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -45,13 +45,22 @@ class PromptRefiner:
45
  {"role": "system", "content": 'You are an expert at refining and extending prompts. Given a basic prompt, provide a more detailed.'},
46
  {"role": "user", "content": selected_meta_prompt.replace("[Insert initial prompt here]", prompt_input.text)}
47
  ]
48
- response = self.client.chat_completion(
49
- model=prompt_refiner_model,
50
- messages=messages,
51
- max_tokens=2000,
52
- temperature=0.8
53
- )
54
- response_content = response.choices[0].message.content.strip()
 
 
 
 
 
 
 
 
 
55
  try:
56
  json_match = re.search(r'<json>\s*(.*?)\s*</json>', response_content, re.DOTALL)
57
  if json_match:
 
45
  {"role": "system", "content": 'You are an expert at refining and extending prompts. Given a basic prompt, provide a more detailed.'},
46
  {"role": "user", "content": selected_meta_prompt.replace("[Insert initial prompt here]", prompt_input.text)}
47
  ]
48
+ try:
49
+ response = self.client.chat_completion(
50
+ model=prompt_refiner_model,
51
+ messages=messages,
52
+ max_tokens=2000,
53
+ temperature=0.8
54
+ )
55
+ response_content = response.choices[0].message.content.strip()
56
+ except HfHubHTTPError as e:
57
+ return (
58
+ "Error: Model timeout. Please try a smaller model or try again later.",
59
+ "",
60
+ "The selected model is currently experiencing high traffic.",
61
+ {}
62
+ )
63
+
64
  try:
65
  json_match = re.search(r'<json>\s*(.*?)\s*</json>', response_content, re.DOTALL)
66
  if json_match: