Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,6 +20,19 @@ css = """
|
|
| 20 |
}
|
| 21 |
"""
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
system_message = """
|
| 24 |
As an AI Prompt Engineering Tutor, your role is to guide the user through an interactive learning journey to master prompt engineering techniques. You will progressively challenge the user to write prompts, provide feedback, and offer tailored tips for improvement based on their previous responses.
|
| 25 |
|
|
@@ -85,10 +98,18 @@ if not api_token:
|
|
| 85 |
|
| 86 |
client = InferenceClient("meta-llama/Meta-Llama-3-70B-Instruct", token=api_token)
|
| 87 |
|
| 88 |
-
def respond(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
messages = [{"role": "system", "content": system_message}]
|
| 90 |
|
| 91 |
-
for user_msg, assistant_msg in
|
| 92 |
messages.append({"role": "user", "content": user_msg})
|
| 93 |
messages.append({"role": "assistant", "content": assistant_msg})
|
| 94 |
|
|
@@ -98,40 +119,69 @@ def respond(message, chat_history):
|
|
| 98 |
|
| 99 |
for message in client.chat_completion(
|
| 100 |
messages,
|
| 101 |
-
max_tokens=
|
| 102 |
stream=True,
|
| 103 |
-
temperature=
|
| 104 |
-
top_p=
|
| 105 |
):
|
| 106 |
token = message.choices[0].delta.content
|
| 107 |
response += token
|
| 108 |
yield response
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
if __name__ == "__main__":
|
| 137 |
demo.launch(share=True)
|
|
|
|
| 20 |
}
|
| 21 |
"""
|
| 22 |
|
| 23 |
+
PLACEHOLDER = """
|
| 24 |
+
<div class="message-bubble-border" style="display:flex; max-width: 600px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); backdrop-filter: blur(10px);">
|
| 25 |
+
<figure style="margin: 0;">
|
| 26 |
+
<img src="https://huggingface.co/spaces/baconnier/Finance/resolve/main/banker.jpg" style="width: 100%; height: 100%; border-radius: 8px;">
|
| 27 |
+
</figure>
|
| 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;">AI Prompt Engineering Tutor is trained to guide you through mastering prompt engineering techniques. Use this for learning purposes only.</p>
|
| 32 |
+
</div>
|
| 33 |
+
</div>
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
system_message = """
|
| 37 |
As an AI Prompt Engineering Tutor, your role is to guide the user through an interactive learning journey to master prompt engineering techniques. You will progressively challenge the user to write prompts, provide feedback, and offer tailored tips for improvement based on their previous responses.
|
| 38 |
|
|
|
|
| 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 user_msg, assistant_msg in history:
|
| 113 |
messages.append({"role": "user", "content": user_msg})
|
| 114 |
messages.append({"role": "assistant", "content": assistant_msg})
|
| 115 |
|
|
|
|
| 119 |
|
| 120 |
for message in client.chat_completion(
|
| 121 |
messages,
|
| 122 |
+
max_tokens=max_tokens,
|
| 123 |
stream=True,
|
| 124 |
+
temperature=temperature,
|
| 125 |
+
top_p=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",
|
| 167 |
+
block_border_width="1px",
|
| 168 |
+
block_title_background_fill_dark="#070d1b",
|
| 169 |
+
button_secondary_background_fill_dark="#070d1b",
|
| 170 |
+
border_color_primary_dark="#21293b",
|
| 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 |
+
title="AI Prompt Engineering Tutor",
|
| 182 |
+
description="Master the art of crafting effective prompts",
|
| 183 |
+
chatbot=gr.Chatbot(scale=1, placeholder=PLACEHOLDER)
|
| 184 |
+
)
|
| 185 |
|
| 186 |
if __name__ == "__main__":
|
| 187 |
demo.launch(share=True)
|