mikemin027 commited on
Commit
24ded4f
·
verified ·
1 Parent(s): 69728e9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ from llama_cpp import Llama
4
+
5
+ # Initialize the InferenceClient
6
+ client = InferenceClient()
7
+
8
+ llm = Llama.from_pretrained(
9
+ repo_id="mradermacher/OpenELM-1_1B-Instruct-GGUF",
10
+ filename="OpenELM-1_1B-Instruct.Q4_K_M.gguf",
11
+ )
12
+
13
+ def respond(
14
+ message,
15
+ history: list[tuple[str, str]],
16
+ system_message,
17
+ max_tokens,
18
+ temperature,
19
+ top_p,
20
+ ):
21
+ messages = [{"role": "system", "content": system_message}]
22
+
23
+ for val in history:
24
+ if val[0]:
25
+ messages.append({"role": "user", "content": val[0]})
26
+ if val[1]:
27
+ messages.append({"role": "assistant", "content": val[1]})
28
+
29
+ messages.append({"role": "user", "content": message})
30
+
31
+ response = ""
32
+
33
+ # Use the client to get the chat completion
34
+ for message in client.chat_completion(
35
+ messages,
36
+ max_tokens=max_tokens,
37
+ stream=True,
38
+ temperature=temperature,
39
+ top_p=top_p,
40
+ ):
41
+ token = message['choices'][0]['delta']['content']
42
+ response += token
43
+ yield response
44
+
45
+ demo = gr.ChatInterface(
46
+ respond,
47
+ additional_inputs=[
48
+ gr.Textbox(value="You are a friendly, conversational, helpful, and informative chatbot, designed to help users as best as possible. Responses should be fun to read, including the use of appropriate emojis in answers, wherever necesssary.", label="System message"),
49
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
51
+ gr.Slider(
52
+ minimum=0.1,
53
+ maximum=1.0,
54
+ value=0.95,
55
+ step=0.05,
56
+ label="Top-p (nucleus sampling)",
57
+ ),
58
+ ],
59
+ )
60
+
61
+ if __name__ == "__main__":
62
+ demo.launch()