Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
history: list[tuple[str, str]],
|
| 9 |
-
system_message,
|
| 10 |
max_tokens,
|
| 11 |
temperature,
|
| 12 |
top_p,
|
| 13 |
):
|
| 14 |
-
messages = [{"role": "system", "content": system_message}]
|
| 15 |
-
|
| 16 |
-
for val in history:
|
| 17 |
-
if val[0]:
|
| 18 |
-
messages.append({"role": "user", "content": val[0]})
|
| 19 |
-
if val[1]:
|
| 20 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 21 |
-
|
| 22 |
-
messages.append({"role": "user", "content": message})
|
| 23 |
-
|
| 24 |
response = ""
|
| 25 |
|
| 26 |
for message in client.chat_completion(
|
| 27 |
-
|
| 28 |
max_tokens=max_tokens,
|
| 29 |
stream=True,
|
| 30 |
temperature=temperature,
|
|
@@ -33,27 +21,29 @@ def respond(
|
|
| 33 |
token = message.choices[0].delta.content
|
| 34 |
|
| 35 |
response += token
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 46 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 47 |
-
gr.Slider(
|
| 48 |
-
minimum=0.1,
|
| 49 |
-
maximum=1.0,
|
| 50 |
-
value=0.95,
|
| 51 |
-
step=0.05,
|
| 52 |
-
label="Top-p (nucleus sampling)",
|
| 53 |
-
),
|
| 54 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
)
|
| 56 |
|
| 57 |
-
|
| 58 |
if __name__ == "__main__":
|
| 59 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
|
| 4 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 5 |
|
| 6 |
+
def generate_prompt(
|
| 7 |
+
prompt,
|
|
|
|
|
|
|
| 8 |
max_tokens,
|
| 9 |
temperature,
|
| 10 |
top_p,
|
| 11 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
response = ""
|
| 13 |
|
| 14 |
for message in client.chat_completion(
|
| 15 |
+
[{"role": "user", "content": prompt}],
|
| 16 |
max_tokens=max_tokens,
|
| 17 |
stream=True,
|
| 18 |
temperature=temperature,
|
|
|
|
| 21 |
token = message.choices[0].delta.content
|
| 22 |
|
| 23 |
response += token
|
| 24 |
+
return response
|
| 25 |
|
| 26 |
+
# Define the Gradio interface
|
| 27 |
+
demo = gr.Interface(
|
| 28 |
+
generate_prompt,
|
| 29 |
+
inputs=[
|
| 30 |
+
gr.Textbox(label="Input your prompt", lines=7, placeholder="Type your prompt here..."),
|
|
|
|
|
|
|
| 31 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 32 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 33 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
],
|
| 35 |
+
outputs=gr.Textbox(label="Generated Prompt", lines=10),
|
| 36 |
+
title="Expert Prompt Engineering",
|
| 37 |
+
theme="compact", # Adjust theme as desired
|
| 38 |
+
description="Input a prompt and generate a well-crafted response.",
|
| 39 |
+
example=[
|
| 40 |
+
"Act as an expert in prompt engineering. Your task is to deeply understand what the user wants, and in return respond with a well-crafted prompt that, if fed to a separate AI, will get the exact result the user desires.",
|
| 41 |
+
512,
|
| 42 |
+
0.7,
|
| 43 |
+
0.95
|
| 44 |
+
],
|
| 45 |
+
button_text="Generate Prompt"
|
| 46 |
)
|
| 47 |
|
|
|
|
| 48 |
if __name__ == "__main__":
|
| 49 |
+
demo.launch()
|