Armando Medina commited on
Commit
16db460
·
1 Parent(s): b87b031

updatef for llmam

Browse files
Files changed (1) hide show
  1. app.py +26 -42
app.py CHANGED
@@ -2,66 +2,50 @@ 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
- client = InferenceClient('one1cat/FineTunes_LLM_CFR_49')
 
10
 
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
- for message in client.chat_completion(
34
- messages,
35
- max_tokens=max_tokens,
36
- stream=True,
37
- temperature=temperature,
38
- top_p=top_p,
39
- ):
40
- token = message.choices[0].delta.content
 
 
41
 
42
- response += token
43
- yield response
44
 
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
-
66
  if __name__ == "__main__":
67
  demo.launch()
 
2
  from huggingface_hub import InferenceClient
3
 
4
  """
5
+ For more information on `huggingface_hub` Inference API support, check:
6
+ https://huggingface.co/docs/huggingface_hub/en/guides/inference
7
  """
 
8
 
9
+ # Initialize the Inference API Client with your model
10
+ client = InferenceClient("one1cat/FineTunes_LLM_CFR_49")
11
 
12
 
13
+ def respond(message, history, system_message, max_tokens, temperature, top_p):
14
+ """
15
+ Generates responses using the fine-tuned CFR 49 model.
16
+ """
17
 
18
+ # Format prompt
19
+ prompt = f"{system_message}\n\nUser: {message}\n\nAssistant:"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ # Generate response
22
  response = ""
23
 
24
+ try:
25
+ for token in client.text_generation(
26
+ prompt,
27
+ max_new_tokens=max_tokens,
28
+ temperature=temperature,
29
+ top_p=top_p,
30
+ stream=True, # Enables token streaming
31
+ ):
32
+ response += token
33
+ yield response
34
 
35
+ except Exception as e:
36
+ yield f"Error: {str(e)}"
37
 
38
 
39
+ # Gradio Chat Interface
 
 
40
  demo = gr.ChatInterface(
41
  respond,
42
  additional_inputs=[
43
+ gr.Textbox(value="You are an AI trained on CFR 49 regulations.", label="System message"),
44
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
45
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
46
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
 
 
 
 
 
47
  ],
48
  )
49
 
 
50
  if __name__ == "__main__":
51
  demo.launch()