mikemin027 commited on
Commit
3eee526
1 Parent(s): b4ed75c

Attempt at fixing Client NameError #1

Browse files
Files changed (1) hide show
  1. app.py +14 -23
app.py CHANGED
@@ -2,19 +2,14 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  from llama_cpp import Llama
4
 
 
5
  llm = Llama.from_pretrained(
6
- repo_id="bartowski/Ministral-8B-Instruct-2410-GGUF",
7
- filename="Ministral-8B-Instruct-2410-Q4_K_M.gguf",
8
- )
9
- llm.create_chat_completion(
10
- messages = [
11
- {
12
- "role": "user",
13
- "content": "What is the capital of France?"
14
- }
15
- ]
16
  )
17
 
 
 
18
 
19
  def respond(
20
  message,
@@ -34,25 +29,22 @@ def respond(
34
 
35
  messages.append({"role": "user", "content": message})
36
 
37
- response = ""
38
-
39
- for message in client.chat_completion(
40
- messages,
41
  max_tokens=max_tokens,
42
- stream=True,
43
  temperature=temperature,
44
  top_p=top_p,
45
- ):
46
- token = message.choices[0].delta.content
47
-
48
- response += token
49
- yield response
50
 
 
 
51
 
52
  demo = gr.ChatInterface(
53
  respond,
54
  additional_inputs=[
55
- gr.Textbox(value="You are a friendly, conversational chatbot who utitilizes relevant information and emojis to build efficient conversations.", label="System message"),
56
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
57
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
58
  gr.Slider(
@@ -65,6 +57,5 @@ demo = gr.ChatInterface(
65
  ],
66
  )
67
 
68
-
69
  if __name__ == "__main__":
70
- demo.launch()
 
2
  from huggingface_hub import InferenceClient
3
  from llama_cpp import Llama
4
 
5
+ # Initialize the Llama model
6
  llm = Llama.from_pretrained(
7
+ repo_id="bartowski/Ministral-8B-Instruct-2410-GGUF",
8
+ filename="Ministral-8B-Instruct-2410-Q4_K_M.gguf",
 
 
 
 
 
 
 
 
9
  )
10
 
11
+ # Initialize the inference client
12
+ client = InferenceClient(model="bartowski/Ministral-8B-Instruct-2410-GGUF")
13
 
14
  def respond(
15
  message,
 
29
 
30
  messages.append({"role": "user", "content": message})
31
 
32
+ # Use llm for chat completion
33
+ response = llm.create_chat_completion(
34
+ messages=messages,
 
35
  max_tokens=max_tokens,
 
36
  temperature=temperature,
37
  top_p=top_p,
38
+ stream=True,
39
+ )
 
 
 
40
 
41
+ for token in response:
42
+ yield token['choices'][0]['delta']['content']
43
 
44
  demo = gr.ChatInterface(
45
  respond,
46
  additional_inputs=[
47
+ gr.Textbox(value="You are a friendly, conversational chatbot who utilizes relevant information and emojis to build efficient conversations.", label="System message"),
48
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
49
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
50
  gr.Slider(
 
57
  ],
58
  )
59
 
 
60
  if __name__ == "__main__":
61
+ demo.launch()