halimbahae commited on
Commit
f703262
·
verified ·
1 Parent(s): 4993542

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -33
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 respond(
7
- message,
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
- messages,
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
- yield response
37
 
38
- demo = gr.ChatInterface(
39
- respond,
40
- additional_inputs=[
41
- gr.Textbox(value="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. ### Task: {task} ### Context: Make sure to include *any* context that is needed for the LLM to accurately, and reliably respond as needed. ### Response format: Outline the ideal response format for this prompt. ### Important Notes: - Instruct the model to list out its thoughts before giving an answer. - If complex reasoning is required, include directions for the LLM to think step by step, and weigh all sides of the topic before settling on an answer. - Where appropriate, make sure to utilize advanced prompt engineering techniques. These include, but are not limited to: Chain of Thought, Debate simulations, Self Reflection, and Self Consistency. - Strictly use text, no code please ### Input: [Type here what you want from the model]", label="System message"),
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()