rosameliacarioni commited on
Commit
232d877
·
1 Parent(s): f2a137b
Files changed (1) hide show
  1. app.py +17 -52
app.py CHANGED
@@ -1,66 +1,31 @@
1
- import gradio as gr
2
  from llama_cpp import Llama
3
- from huggingface_hub import InferenceClient
4
-
5
- """
6
- For more information on ⁠ huggingface_hub ⁠ Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
7
- """
8
 
9
  llm = Llama.from_pretrained(
10
- repo_id="rcarioniporras/test_gguf_model",
11
  filename="unsloth.Q4_K_M.gguf",
12
  )
13
 
14
-
15
- def respond(
16
- message,
17
- history: list[tuple[str, str]],
18
- system_message,
19
- max_tokens,
20
- temperature,
21
- top_p,
22
- ):
23
- messages = [{"role": "system", "content": system_message}]
24
-
25
- for val in history:
26
- if val[0]:
27
- messages.append({"role": "user", "content": val[0]})
28
- if val[1]:
29
- messages.append({"role": "assistant", "content": val[1]})
30
-
31
  messages.append({"role": "user", "content": message})
32
-
33
  response = ""
34
- for message in llm.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
-
43
- response += token
44
  yield response
45
 
46
- """
47
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
48
- """
49
- demo = gr.ChatInterface(
50
- respond,
51
- additional_inputs=[
52
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
53
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
54
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
55
- gr.Slider(
56
- minimum=0.1,
57
- maximum=1.0,
58
- value=0.95,
59
- step=0.05,
60
- label="Top-p (nucleus sampling)",
61
- ),
62
- ],
63
- )
64
 
65
- if __name__ == "main":
66
  demo.launch()
 
 
1
  from llama_cpp import Llama
2
+ import gradio as gr
 
 
 
 
3
 
4
  llm = Llama.from_pretrained(
5
+ repo_id="ericbanzuzi/test_script_llm_gguf",
6
  filename="unsloth.Q4_K_M.gguf",
7
  )
8
 
9
+ def predict(message, history):
10
+ messages = [{"role": "system", "content": "You are a helpful assistant."}]
11
+ for user_message, bot_message in history:
12
+ if user_message:
13
+ messages.append({"role": "user", "content": user_message})
14
+ if bot_message:
15
+ messages.append({"role": "assistant", "content": bot_message})
 
 
 
 
 
 
 
 
 
 
16
  messages.append({"role": "user", "content": message})
17
+
18
  response = ""
19
+ for chunk in llm.create_chat_completion(
 
 
20
  stream=True,
21
+ messages=messages,
 
22
  ):
23
+ part = chunk["choices"][0]["delta"].get("content", None)
24
+ if part:
25
+ response += part
26
  yield response
27
 
28
+ demo = gr.ChatInterface(predict)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ if __name__ == "__main__":
31
  demo.launch()