Testing Top P and System Prompt
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
| 11 |
|
| 12 |
DESCRIPTION = '''
|
| 13 |
<div>
|
| 14 |
-
<h1 style="text-align: center;">
|
| 15 |
</div>
|
| 16 |
'''
|
| 17 |
|
|
@@ -23,7 +23,7 @@ LICENSE = """
|
|
| 23 |
|
| 24 |
PLACEHOLDER = """
|
| 25 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
| 26 |
-
<h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">
|
| 27 |
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
|
| 28 |
</div>
|
| 29 |
"""
|
|
@@ -55,7 +55,9 @@ terminators = [
|
|
| 55 |
def chat_llama3_8b(message: str,
|
| 56 |
history: list,
|
| 57 |
temperature: float,
|
| 58 |
-
max_new_tokens: int
|
|
|
|
|
|
|
| 59 |
) -> str:
|
| 60 |
"""
|
| 61 |
Generate a streaming response using the llama3-8b model.
|
|
@@ -64,10 +66,12 @@ def chat_llama3_8b(message: str,
|
|
| 64 |
history (list): The conversation history used by ChatInterface.
|
| 65 |
temperature (float): The temperature for generating the response.
|
| 66 |
max_new_tokens (int): The maximum number of new tokens to generate.
|
|
|
|
|
|
|
| 67 |
Returns:
|
| 68 |
str: The generated response.
|
| 69 |
"""
|
| 70 |
-
conversation = []
|
| 71 |
for user, assistant in history:
|
| 72 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
| 73 |
conversation.append({"role": "user", "content": message})
|
|
@@ -82,6 +86,7 @@ def chat_llama3_8b(message: str,
|
|
| 82 |
max_new_tokens=max_new_tokens,
|
| 83 |
do_sample=True,
|
| 84 |
temperature=temperature,
|
|
|
|
| 85 |
eos_token_id=terminators,
|
| 86 |
)
|
| 87 |
# This will enforce greedy generation (do_sample=False) when the temperature is passed 0, avoiding the crash.
|
|
@@ -122,6 +127,16 @@ with gr.Blocks(fill_height=True, css=css) as demo:
|
|
| 122 |
value=4096,
|
| 123 |
label="Max new tokens",
|
| 124 |
render=False ),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
],
|
| 126 |
examples=[
|
| 127 |
['Who Are you?']
|
|
@@ -132,4 +147,3 @@ with gr.Blocks(fill_height=True, css=css) as demo:
|
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|
| 134 |
demo.launch()
|
| 135 |
-
|
|
|
|
| 11 |
|
| 12 |
DESCRIPTION = '''
|
| 13 |
<div>
|
| 14 |
+
<h1 style="text-align: center;">Oscar's Model</h1>
|
| 15 |
</div>
|
| 16 |
'''
|
| 17 |
|
|
|
|
| 23 |
|
| 24 |
PLACEHOLDER = """
|
| 25 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
| 26 |
+
<h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">Oscar's Uncensored Model</h1>
|
| 27 |
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
|
| 28 |
</div>
|
| 29 |
"""
|
|
|
|
| 55 |
def chat_llama3_8b(message: str,
|
| 56 |
history: list,
|
| 57 |
temperature: float,
|
| 58 |
+
max_new_tokens: int,
|
| 59 |
+
top_p: float,
|
| 60 |
+
system_prompt: str
|
| 61 |
) -> str:
|
| 62 |
"""
|
| 63 |
Generate a streaming response using the llama3-8b model.
|
|
|
|
| 66 |
history (list): The conversation history used by ChatInterface.
|
| 67 |
temperature (float): The temperature for generating the response.
|
| 68 |
max_new_tokens (int): The maximum number of new tokens to generate.
|
| 69 |
+
top_p (float): The top_p value for nucleus sampling.
|
| 70 |
+
system_prompt (str): The system prompt to guide the conversation.
|
| 71 |
Returns:
|
| 72 |
str: The generated response.
|
| 73 |
"""
|
| 74 |
+
conversation = [{"role": "system", "content": system_prompt}]
|
| 75 |
for user, assistant in history:
|
| 76 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
| 77 |
conversation.append({"role": "user", "content": message})
|
|
|
|
| 86 |
max_new_tokens=max_new_tokens,
|
| 87 |
do_sample=True,
|
| 88 |
temperature=temperature,
|
| 89 |
+
top_p=top_p,
|
| 90 |
eos_token_id=terminators,
|
| 91 |
)
|
| 92 |
# This will enforce greedy generation (do_sample=False) when the temperature is passed 0, avoiding the crash.
|
|
|
|
| 127 |
value=4096,
|
| 128 |
label="Max new tokens",
|
| 129 |
render=False ),
|
| 130 |
+
gr.Slider(minimum=0,
|
| 131 |
+
maximum=1,
|
| 132 |
+
step=0.1,
|
| 133 |
+
value=0.9,
|
| 134 |
+
label="Top_p",
|
| 135 |
+
render=False),
|
| 136 |
+
gr.Textbox(lines=2,
|
| 137 |
+
placeholder="Enter system prompt here...",
|
| 138 |
+
label="System Prompt",
|
| 139 |
+
render=False),
|
| 140 |
],
|
| 141 |
examples=[
|
| 142 |
['Who Are you?']
|
|
|
|
| 147 |
|
| 148 |
if __name__ == "__main__":
|
| 149 |
demo.launch()
|
|
|