NooneImportant commited on
Commit
600b924
1 Parent(s): 2d4632e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import InferenceClient
2
+ import gradio as gr
3
+
4
+ client = InferenceClient("cutycat2000/MeowGPT-2")
5
+
6
+
7
+ def format_prompt(message, history):
8
+ prompt = "<s>"
9
+ for user_prompt, bot_response in history:
10
+ prompt += f"<s>[|User|]{user_prompt}</s>"
11
+ prompt += f"[|Assistant|] {bot_response} "
12
+ prompt += f"<s>[|User|]{message}</s>[|Assistant|]"
13
+ return prompt
14
+
15
+ def generate(
16
+ prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
17
+ ):
18
+ temperature = float(temperature)
19
+ if temperature < 1e-2:
20
+ temperature = 1e-2
21
+ top_p = float(top_p)
22
+
23
+ generate_kwargs = dict(
24
+ temperature=temperature,
25
+ max_new_tokens=max_new_tokens,
26
+ top_p=top_p,
27
+ repetition_penalty=repetition_penalty,
28
+ do_sample=True,
29
+ )
30
+
31
+ formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
32
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, details=True, return_full_text=False)
33
+ output = ""
34
+
35
+ for response in stream:
36
+ output += response
37
+ yield output
38
+ return output
39
+
40
+
41
+ additional_inputs=[
42
+ gr.Textbox(
43
+ label="System Prompt",
44
+ max_lines=1,
45
+ interactive=True,
46
+ ),
47
+ gr.Slider(
48
+ label="Temperature",
49
+ value=0.9,
50
+ minimum=0.0,
51
+ maximum=1.0,
52
+ step=0.05,
53
+ interactive=True,
54
+ info="Higher values produce more diverse outputs",
55
+ ),
56
+ gr.Slider(
57
+ label="Max new tokens",
58
+ value=192,
59
+ minimum=0,
60
+ maximum=192,
61
+ step=8,
62
+ interactive=True,
63
+ info="The maximum numbers of new tokens",
64
+ ),
65
+ gr.Slider(
66
+ label="Top-p (nucleus sampling)",
67
+ value=0.90,
68
+ minimum=0.0,
69
+ maximum=1,
70
+ step=0.05,
71
+ interactive=True,
72
+ info="Higher values sample more low-probability tokens",
73
+ ),
74
+ gr.Slider(
75
+ label="Repetition penalty",
76
+ value=1.2,
77
+ minimum=1.0,
78
+ maximum=2.0,
79
+ step=0.05,
80
+ interactive=True,
81
+ info="Penalize repeated tokens",
82
+ )
83
+ ]
84
+
85
+ examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
86
+ ["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None,],
87
+ ["I'm trying to learn French. Can you provide some common phrases that would be useful for a beginner, along with their pronunciations?", None, None, None, None, None,],
88
+ ["I have chicken, rice, and bell peppers in my kitchen. Can you suggest an easy recipe I can make with these ingredients?", None, None, None, None, None,],
89
+ ["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None,],
90
+ ["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
91
+ ]
92
+
93
+ gr.ChatInterface(
94
+ fn=generate,
95
+ chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
96
+ additional_inputs=additional_inputs,
97
+ title="cutycat2000/MeowGPT-2",
98
+ examples=examples,
99
+ concurrency_limit=20,
100
+ ).launch(show_api=False)