Grandediw commited on
Commit
af9ddfc
·
2 Parent(s): b59fc7f 7ee16c9
Files changed (2) hide show
  1. app.py +51 -28
  2. requirements.txt +3 -1
app.py CHANGED
@@ -4,17 +4,9 @@ from huggingface_hub import InferenceClient
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("jacopoda/lora_model")
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:
@@ -35,30 +27,61 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
40
  yield response
41
 
42
-
43
  """
44
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
  """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
60
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
 
 
 
 
62
 
63
  if __name__ == "__main__":
64
- demo.launch()
 
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("Grandediw/lora_model")
8
 
9
+ def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
 
 
 
 
 
 
 
 
10
  messages = [{"role": "system", "content": system_message}]
11
 
12
  for val in history:
 
27
  top_p=top_p,
28
  ):
29
  token = message.choices[0].delta.content
 
30
  response += token
31
  yield response
32
 
 
33
  """
34
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
35
  """
36
+ with gr.Blocks(title="Enhanced LORA Chat Interface") as demo:
37
+ gr.Markdown(
38
+ """
39
+ # LORA Chat Assistant
40
+ Welcome! This is a demo of a LORA-based Chat Assistant.
41
+ Start by entering your prompt in the chat box below.
42
+ """
43
+ )
44
+
45
+ with gr.Row():
46
+ # Left column: Chat interface
47
+ with gr.Column():
48
+ chat = gr.ChatInterface(
49
+ fn=respond,
50
+ additional_inputs=[],
51
+ height=500
52
+ )
53
+
54
+ # Right column: Settings and System Message
55
+ with gr.Column():
56
+ gr.Markdown("### Configuration")
57
+ system_message = gr.Textbox(
58
+ value="You are a friendly Chatbot.",
59
+ label="Initial Behavior (System Message)",
60
+ lines=3,
61
+ placeholder="Describe how the assistant should behave..."
62
+ )
63
+
64
+ with gr.Accordion("Advanced Settings", open=False):
65
+ max_tokens = gr.Slider(
66
+ minimum=1, maximum=2048, value=512, step=1,
67
+ label="Max new tokens",
68
+ info="Controls the maximum number of tokens in the response."
69
+ )
70
+ temperature = gr.Slider(
71
+ minimum=0.1, maximum=4.0, value=0.7, step=0.1,
72
+ label="Temperature",
73
+ info="Higher values produce more random outputs."
74
+ )
75
+ top_p = gr.Slider(
76
+ minimum=0.1, maximum=1.0, value=0.95, step=0.05,
77
+ label="Top-p (nucleus sampling)",
78
+ info="Limits the tokens considered to the top portion by cumulative probability."
79
+ )
80
 
81
+ # Link parameters to the chat interface's function
82
+ chat.configure(
83
+ additional_inputs=[system_message, max_tokens, temperature, top_p]
84
+ )
85
 
86
  if __name__ == "__main__":
87
+ demo.launch()
requirements.txt CHANGED
@@ -1 +1,3 @@
1
- huggingface_hub==0.25.2
 
 
 
1
+ huggingface_hub==0.25.2
2
+ unsloth
3
+ gradio