Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ except Exception as e:
|
|
| 18 |
base_model = None
|
| 19 |
peft_model = None
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 24 |
global tokenizer, peft_model
|
|
@@ -46,30 +46,31 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 46 |
top_p=top_p,
|
| 47 |
do_sample=True
|
| 48 |
)
|
| 49 |
-
|
| 50 |
# Get the last message from the generated text
|
| 51 |
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 52 |
-
def extract_content_after_output(text):
|
| 53 |
-
"""
|
| 54 |
-
Extracts and returns the content that follows the word 'output' in the given text.
|
| 55 |
-
If 'output' is not found, returns an empty string.
|
| 56 |
-
"""
|
| 57 |
-
# Define the regular expression pattern to match 'output' and capture everything after it
|
| 58 |
-
pattern = re.compile(r'output\s*:\s*(.*)', re.IGNORECASE | re.DOTALL)
|
| 59 |
-
match = pattern.search(text)
|
| 60 |
-
if match:
|
| 61 |
-
# Return the captured group, which is the content after 'output'
|
| 62 |
-
return match.group(1).strip()
|
| 63 |
-
else:
|
| 64 |
-
# If 'output' is not found, return an empty string
|
| 65 |
-
return "Retry to get output, the model failed to generated required output(This occurs rarely🤷♂️)"
|
| 66 |
-
|
| 67 |
-
lines = extract_user_content(generated_text)
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
demo = gr.ChatInterface(
|
| 75 |
respond,
|
|
|
|
| 18 |
base_model = None
|
| 19 |
peft_model = None
|
| 20 |
|
| 21 |
+
|
| 22 |
|
| 23 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 24 |
global tokenizer, peft_model
|
|
|
|
| 46 |
top_p=top_p,
|
| 47 |
do_sample=True
|
| 48 |
)
|
| 49 |
+
generated_text = None
|
| 50 |
# Get the last message from the generated text
|
| 51 |
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
def extract_content_after_output(text):
|
| 54 |
+
"""
|
| 55 |
+
Extracts and returns the content that follows the word 'output' in the given text.
|
| 56 |
+
If 'output' is not found, returns an empty string.
|
| 57 |
+
"""
|
| 58 |
+
# Define the regular expression pattern to match 'output' and capture everything after it
|
| 59 |
+
pattern = re.compile(r'output\s*:\s*(.*)', re.IGNORECASE | re.DOTALL)
|
| 60 |
+
match = pattern.search(text)
|
| 61 |
+
if match:
|
| 62 |
+
# Return the captured group, which is the content after 'output'
|
| 63 |
+
return match.group(1).strip()
|
| 64 |
+
else:
|
| 65 |
+
# If 'output' is not found, return an empty string
|
| 66 |
+
return "Retry to get output, the model failed to generated required output(This occurs rarely🤷♂️)"
|
| 67 |
+
|
| 68 |
+
lines = extract_user_content(generated_text)
|
| 69 |
+
|
| 70 |
+
return lines
|
| 71 |
|
| 72 |
+
except Exception as e:
|
| 73 |
+
return f"Generation error: {e}"
|
| 74 |
|
| 75 |
demo = gr.ChatInterface(
|
| 76 |
respond,
|