mikemin027 commited on
Commit
15b3be2
·
verified ·
1 Parent(s): ccf4149

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -19
app.py CHANGED
@@ -2,21 +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/Reasoning-Llama-1b-v0.1-GGUF",
7
- filename="Reasoning-Llama-1b-v0.1-f16.gguf",
8
- )
9
 
10
- llm.create_chat_completion(
11
- messages = [
12
- {
13
- "role": "user",
14
- "content": "What is the capital of France?"
15
- }
16
- ]
17
  )
18
 
19
-
20
  def respond(
21
  message,
22
  history: list[tuple[str, str]],
@@ -37,6 +30,7 @@ def respond(
37
 
38
  response = ""
39
 
 
40
  for message in client.chat_completion(
41
  messages,
42
  max_tokens=max_tokens,
@@ -44,15 +38,10 @@ def respond(
44
  temperature=temperature,
45
  top_p=top_p,
46
  ):
47
- token = message.choices[0].delta.content
48
-
49
  response += token
50
  yield response
51
 
52
-
53
- """
54
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
55
- """
56
  demo = gr.ChatInterface(
57
  respond,
58
  additional_inputs=[
@@ -69,6 +58,5 @@ demo = gr.ChatInterface(
69
  ],
70
  )
71
 
72
-
73
  if __name__ == "__main__":
74
  demo.launch()
 
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="bartowski/Reasoning-Llama-1b-v0.1-GGUF",
10
+ filename="Reasoning-Llama-1b-v0.1-f16.gguf",
 
 
 
 
11
  )
12
 
 
13
  def respond(
14
  message,
15
  history: list[tuple[str, str]],
 
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,
 
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=[
 
58
  ],
59
  )
60
 
 
61
  if __name__ == "__main__":
62
  demo.launch()