halimbahae commited on
Commit
4993542
1 Parent(s): fa54661

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +59 -0
app2.py CHANGED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,
31
+ top_p=top_p,
32
+ ):
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()