onrdmr commited on
Commit
573fa66
·
verified ·
1 Parent(s): 236bb15

Update app.py

Browse files

ilk deneme için.

Files changed (1) hide show
  1. app.py +55 -38
app.py CHANGED
@@ -1,43 +1,60 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
3
 
4
  """
5
  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
6
  """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
 
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- messages.append({"role": "user", "content": message})
27
 
28
- response = ""
 
 
 
 
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
 
42
  """
43
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
@@ -46,15 +63,15 @@ demo = gr.ChatInterface(
46
  respond,
47
  additional_inputs=[
48
  gr.Textbox(value="You are a friendly Chatbot.", 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
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ from llama_cpp import Llama
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
+ # client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
 
10
 
11
+ # Define the inference parameters
12
+ inference_params = {
13
+ "n_threads": 4,
14
+ "n_predict": -1,
15
+ "top_k": 40,
16
+ "min_p": 0.05,
17
+ "top_p": 0.95,
18
+ "temp": 0.8,
19
+ "repeat_penalty": 1.1,
20
+ "input_prefix": "<|start_header_id|>user<|end_header_id|>\\n\\n",
21
+ "input_suffix": "<|eot_id|><|start_header_id|>assistant<|end_header_id|>\\n\\n",
22
+ "antiprompt": [],
23
+ "pre_prompt": "Sen bir yapay zeka asistanısın. Kullanıcı sana bir görev verecek. Amacın görevi olabildiğince sadık bir şekilde tamamlamak.",
24
+ "pre_prompt_suffix": "<|eot_id|>",
25
+ "pre_prompt_prefix": "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\\n\\n",
26
+ "seed": -1,
27
+ "tfs_z": 1,
28
+ "typical_p": 1,
29
+ "repeat_last_n": 64,
30
+ "frequency_penalty": 0,
31
+ "presence_penalty": 0,
32
+ "n_keep": 0,
33
+ "logit_bias": {},
34
+ "mirostat": 0,
35
+ "mirostat_tau": 5,
36
+ "mirostat_eta": 0.1,
37
+ "memory_f16": True,
38
+ "multiline_input": False,
39
+ "penalize_nl": True
40
+ }
41
 
 
42
 
43
+ llama = Llama.from_pretrained(
44
+ repo_id="ytu-ce-cosmos/Turkish-Llama-8b-Instruct-v0.1-GGUF",
45
+ filename="*Q4_K.gguf",
46
+ verbose=False
47
+ )
48
 
49
+ def respond(
50
+ message
51
+ ):
52
+ # Construct the prompt
53
+ prompt = f"{inference_params['pre_prompt_prefix']}{inference_params['pre_prompt']}\n\n{inference_params['input_prefix']}{message}{inference_params['input_suffix']}"
54
+
55
+ # Generate the response
56
+ response = llama(prompt)
57
+ yield response
 
 
58
 
59
  """
60
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
63
  respond,
64
  additional_inputs=[
65
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
66
+ #gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
67
+ #gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
68
+ #gr.Slider(
69
+ # minimum=0.1,
70
+ # maximum=1.0,
71
+ # value=0.95,
72
+ # step=0.05,
73
+ # label="Top-p (nucleus sampling)",
74
+ #), # inference parametreleri eklenecek
75
  ],
76
  )
77