Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,7 @@ PLACEHOLDER = """
|
|
| 28 |
<div style="padding: .5rem 1.5rem;">
|
| 29 |
<img src="https://huggingface.co/spaces/baconnier/Finance/resolve/main/banker_plus.jpg" style="width: 100%; height: 10%; border-radius: 8px;">
|
| 30 |
<h2 style="text-align: left; font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem;"> </h2>
|
| 31 |
-
<p style="text-align: left; font-size: 16px; line-height: 1.5; margin-bottom: 15px;">
|
| 32 |
</div>
|
| 33 |
</div>
|
| 34 |
"""
|
|
@@ -92,26 +92,21 @@ Try to be funny, use smart format to answer using bullet points.
|
|
| 92 |
Begin the tutorial by introducing yourself and asking for the first prompt as described above.
|
| 93 |
"""
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
| 99 |
client = InferenceClient("meta-llama/Meta-Llama-3-70B-Instruct", token=api_token)
|
| 100 |
|
| 101 |
-
def respond(
|
| 102 |
-
message,
|
| 103 |
-
history: list[tuple[str, str]],
|
| 104 |
-
max_tokens,
|
| 105 |
-
temperature,
|
| 106 |
-
top_p,
|
| 107 |
-
top_k,
|
| 108 |
-
repeat_penalty,
|
| 109 |
-
):
|
| 110 |
messages = [{"role": "system", "content": system_message}]
|
| 111 |
|
| 112 |
-
for
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
|
| 116 |
messages.append({"role": "user", "content": message})
|
| 117 |
|
|
@@ -119,48 +114,18 @@ def respond(
|
|
| 119 |
|
| 120 |
for message in client.chat_completion(
|
| 121 |
messages,
|
| 122 |
-
max_tokens=
|
| 123 |
stream=True,
|
| 124 |
-
temperature=
|
| 125 |
-
top_p=
|
| 126 |
):
|
| 127 |
token = message.choices[0].delta.content
|
|
|
|
| 128 |
response += token
|
| 129 |
yield response
|
| 130 |
|
| 131 |
-
examples = [
|
| 132 |
-
["Write a prompt for a creative writing task about a futuristic city."],
|
| 133 |
-
["Create a prompt for generating a business plan for a startup."],
|
| 134 |
-
["Develop a prompt for a data analysis task on climate change."],
|
| 135 |
-
]
|
| 136 |
-
|
| 137 |
demo = gr.ChatInterface(
|
| 138 |
respond,
|
| 139 |
-
additional_inputs=[
|
| 140 |
-
gr.Slider(minimum=1, maximum=8192, value=512, step=1, label="Max tokens"),
|
| 141 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 142 |
-
gr.Slider(
|
| 143 |
-
minimum=0.1,
|
| 144 |
-
maximum=1.0,
|
| 145 |
-
value=0.95,
|
| 146 |
-
step=0.05,
|
| 147 |
-
label="Top-p",
|
| 148 |
-
),
|
| 149 |
-
gr.Slider(
|
| 150 |
-
minimum=0,
|
| 151 |
-
maximum=100,
|
| 152 |
-
value=40,
|
| 153 |
-
step=1,
|
| 154 |
-
label="Top-k",
|
| 155 |
-
),
|
| 156 |
-
gr.Slider(
|
| 157 |
-
minimum=0.0,
|
| 158 |
-
maximum=2.0,
|
| 159 |
-
value=1.1,
|
| 160 |
-
step=0.1,
|
| 161 |
-
label="Repetition penalty",
|
| 162 |
-
),
|
| 163 |
-
],
|
| 164 |
theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue", neutral_hue="gray",font=[gr.themes.GoogleFont("Exo"), "ui-sans-serif", "system-ui", "sans-serif"]).set(
|
| 165 |
body_background_fill_dark="#0f172a",
|
| 166 |
block_background_fill_dark="#0f172a",
|
|
@@ -171,15 +136,12 @@ demo = gr.ChatInterface(
|
|
| 171 |
background_fill_secondary_dark="#0f172a",
|
| 172 |
color_accent_soft_dark="transparent"
|
| 173 |
),
|
| 174 |
-
examples=examples,
|
| 175 |
-
examples_per_page=3,
|
| 176 |
css=css,
|
| 177 |
retry_btn="Retry",
|
| 178 |
undo_btn="Undo",
|
| 179 |
clear_btn="Clear",
|
| 180 |
submit_btn="Send",
|
| 181 |
-
|
| 182 |
-
description="Master the art of crafting effective prompts",
|
| 183 |
chatbot=gr.Chatbot(scale=1, placeholder=PLACEHOLDER)
|
| 184 |
)
|
| 185 |
|
|
|
|
| 28 |
<div style="padding: .5rem 1.5rem;">
|
| 29 |
<img src="https://huggingface.co/spaces/baconnier/Finance/resolve/main/banker_plus.jpg" style="width: 100%; height: 10%; border-radius: 8px;">
|
| 30 |
<h2 style="text-align: left; font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem;"> </h2>
|
| 31 |
+
<p style="text-align: left; font-size: 16px; line-height: 1.5; margin-bottom: 15px;">Banker++ is trained to act like a Senior Banker. Use this template for learning purposes only. Also a Real time version exist</p>
|
| 32 |
</div>
|
| 33 |
</div>
|
| 34 |
"""
|
|
|
|
| 92 |
Begin the tutorial by introducing yourself and asking for the first prompt as described above.
|
| 93 |
"""
|
| 94 |
|
| 95 |
+
if __name__ == '__main__':
|
| 96 |
+
api_token = os.getenv('HF_API_TOKEN2')
|
| 97 |
+
if not api_token:
|
| 98 |
+
raise ValueError("HF_API_TOKEN not found in environment variables")
|
| 99 |
+
|
| 100 |
client = InferenceClient("meta-llama/Meta-Llama-3-70B-Instruct", token=api_token)
|
| 101 |
|
| 102 |
+
def respond(message, history: list[tuple[str, str]]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
messages = [{"role": "system", "content": system_message}]
|
| 104 |
|
| 105 |
+
for val in history:
|
| 106 |
+
if val[0]:
|
| 107 |
+
messages.append({"role": "user", "content": val[0]})
|
| 108 |
+
if val[1]:
|
| 109 |
+
messages.append({"role": "assistant", "content": val[1]})
|
| 110 |
|
| 111 |
messages.append({"role": "user", "content": message})
|
| 112 |
|
|
|
|
| 114 |
|
| 115 |
for message in client.chat_completion(
|
| 116 |
messages,
|
| 117 |
+
max_tokens=512,
|
| 118 |
stream=True,
|
| 119 |
+
temperature=0.7,
|
| 120 |
+
top_p=0.95,
|
| 121 |
):
|
| 122 |
token = message.choices[0].delta.content
|
| 123 |
+
|
| 124 |
response += token
|
| 125 |
yield response
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
demo = gr.ChatInterface(
|
| 128 |
respond,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue", neutral_hue="gray",font=[gr.themes.GoogleFont("Exo"), "ui-sans-serif", "system-ui", "sans-serif"]).set(
|
| 130 |
body_background_fill_dark="#0f172a",
|
| 131 |
block_background_fill_dark="#0f172a",
|
|
|
|
| 136 |
background_fill_secondary_dark="#0f172a",
|
| 137 |
color_accent_soft_dark="transparent"
|
| 138 |
),
|
|
|
|
|
|
|
| 139 |
css=css,
|
| 140 |
retry_btn="Retry",
|
| 141 |
undo_btn="Undo",
|
| 142 |
clear_btn="Clear",
|
| 143 |
submit_btn="Send",
|
| 144 |
+
description="AI Prompt Engineering Tutor: Master the art of crafting effective prompts",
|
|
|
|
| 145 |
chatbot=gr.Chatbot(scale=1, placeholder=PLACEHOLDER)
|
| 146 |
)
|
| 147 |
|