Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,37 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
"""
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
"""
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
system_message="""
|
| 18 |
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.
|
| 19 |
|
| 20 |
1. Initial Assessment:
|
|
@@ -56,7 +74,7 @@ As an AI Prompt Engineering Tutor, your role is to guide the user through an int
|
|
| 56 |
Conclude with a complex prompt-writing task that incorporates all learned techniques. Compare this final prompt to their initial attempt to showcase progress.
|
| 57 |
|
| 58 |
10. Learning Summary:
|
| 59 |
-
|
| 60 |
|
| 61 |
To begin the tutorial, follow these steps:
|
| 62 |
|
|
@@ -72,14 +90,15 @@ Try to be funny, use smart format to answer using bullet points.
|
|
| 72 |
|
| 73 |
Begin the tutorial by introducing yourself and asking for the first prompt as described above.
|
| 74 |
"""
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
| 83 |
messages = [{"role": "system", "content": system_message}]
|
| 84 |
|
| 85 |
for val in history:
|
|
@@ -94,36 +113,36 @@ def respond(
|
|
| 94 |
|
| 95 |
for message in client.chat_completion(
|
| 96 |
messages,
|
| 97 |
-
max_tokens=
|
| 98 |
stream=True,
|
| 99 |
-
temperature=
|
| 100 |
-
top_p=
|
| 101 |
):
|
| 102 |
token = message.choices[0].delta.content
|
| 103 |
|
| 104 |
response += token
|
| 105 |
yield response
|
| 106 |
|
| 107 |
-
|
| 108 |
-
"""
|
| 109 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 110 |
-
"""
|
| 111 |
demo = gr.ChatInterface(
|
| 112 |
respond,
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
)
|
| 126 |
|
| 127 |
-
|
| 128 |
if __name__ == "__main__":
|
| 129 |
-
demo.launch()
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
css = """
|
| 6 |
+
.message-row {
|
| 7 |
+
justify-content: space-evenly !important;
|
| 8 |
+
}
|
| 9 |
+
.message-bubble-border {
|
| 10 |
+
border-radius: 6px !important;
|
| 11 |
+
}
|
| 12 |
+
.dark.message-bubble-border {
|
| 13 |
+
border-color: #21293b !important;
|
| 14 |
+
}
|
| 15 |
+
.dark.user {
|
| 16 |
+
background: #0a1120 !important;
|
| 17 |
+
}
|
| 18 |
+
.dark.assistant {
|
| 19 |
+
background: transparent !important;
|
| 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 |
+
<h2 style="text-align: left; font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem;">AI Prompt Engineering Tutor</h2>
|
| 30 |
+
<p style="text-align: left; font-size: 16px; line-height: 1.5; margin-bottom: 15px;">Your AI tutor for mastering prompt engineering techniques.</p>
|
| 31 |
+
</div>
|
| 32 |
+
</div>
|
| 33 |
+
"""
|
| 34 |
|
| 35 |
+
system_message = """
|
| 36 |
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.
|
| 37 |
|
| 38 |
1. Initial Assessment:
|
|
|
|
| 74 |
Conclude with a complex prompt-writing task that incorporates all learned techniques. Compare this final prompt to their initial attempt to showcase progress.
|
| 75 |
|
| 76 |
10. Learning Summary:
|
| 77 |
+
Provide a comprehensive review of the user's journey, highlighting key improvements and areas for continued practice.
|
| 78 |
|
| 79 |
To begin the tutorial, follow these steps:
|
| 80 |
|
|
|
|
| 90 |
|
| 91 |
Begin the tutorial by introducing yourself and asking for the first prompt as described above.
|
| 92 |
"""
|
| 93 |
+
|
| 94 |
+
if __name__ == '__main__':
|
| 95 |
+
api_token = os.getenv('HF_API_TOKEN2')
|
| 96 |
+
if not api_token:
|
| 97 |
+
raise ValueError("HF_API_TOKEN not found in environment variables")
|
| 98 |
+
|
| 99 |
+
client = InferenceClient("meta-llama/Meta-Llama-3-70B-Instruct", token=api_token)
|
| 100 |
+
|
| 101 |
+
def respond(message, history: list[tuple[str, str]]):
|
| 102 |
messages = [{"role": "system", "content": system_message}]
|
| 103 |
|
| 104 |
for val in history:
|
|
|
|
| 113 |
|
| 114 |
for message in client.chat_completion(
|
| 115 |
messages,
|
| 116 |
+
max_tokens=512,
|
| 117 |
stream=True,
|
| 118 |
+
temperature=0.7,
|
| 119 |
+
top_p=0.95,
|
| 120 |
):
|
| 121 |
token = message.choices[0].delta.content
|
| 122 |
|
| 123 |
response += token
|
| 124 |
yield response
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
demo = gr.ChatInterface(
|
| 127 |
respond,
|
| 128 |
+
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(
|
| 129 |
+
body_background_fill_dark="#0f172a",
|
| 130 |
+
block_background_fill_dark="#0f172a",
|
| 131 |
+
block_border_width="1px",
|
| 132 |
+
block_title_background_fill_dark="#070d1b",
|
| 133 |
+
button_secondary_background_fill_dark="#070d1b",
|
| 134 |
+
border_color_primary_dark="#21293b",
|
| 135 |
+
background_fill_secondary_dark="#0f172a",
|
| 136 |
+
color_accent_soft_dark="transparent"
|
| 137 |
+
),
|
| 138 |
+
css=css,
|
| 139 |
+
retry_btn="Retry",
|
| 140 |
+
undo_btn="Undo",
|
| 141 |
+
clear_btn="Clear",
|
| 142 |
+
submit_btn="Send",
|
| 143 |
+
description="AI Prompt Engineering Tutor: Master the art of crafting effective prompts",
|
| 144 |
+
chatbot=gr.Chatbot(scale=1, placeholder=PLACEHOLDER)
|
| 145 |
)
|
| 146 |
|
|
|
|
| 147 |
if __name__ == "__main__":
|
| 148 |
+
demo.launch()
|