lahiruchamika27 commited on
Commit
7efecbe
·
verified ·
1 Parent(s): 291bb56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -1,11 +1,14 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
- HF_Token = os.getenv("HF_Token")
5
- # Initialize the inference client with a publicly available chat model
 
 
 
6
  client = InferenceClient(
7
- model="facebook/blenderbot-400M-distill", # Using LLaMA 2 chat model
8
- token=HF_Token # Add your HF token if you have access to LLaMA 2
9
  )
10
 
11
  def respond(
@@ -17,7 +20,7 @@ def respond(
17
  top_p,
18
  ):
19
  """
20
- Generate responses for the chatbot using the LLaMA 2 chat model.
21
 
22
  Args:
23
  message (str): The current user input message
@@ -29,17 +32,14 @@ def respond(
29
  """
30
  # Format the conversation history into messages
31
  messages = [{"role": "system", "content": system_message}]
32
-
33
  for val in history:
34
  if val[0]:
35
  messages.append({"role": "user", "content": val[0]})
36
  if val[1]:
37
  messages.append({"role": "assistant", "content": val[1]})
38
-
39
  messages.append({"role": "user", "content": message})
40
-
41
  response = ""
42
-
43
  # Stream the response tokens
44
  for message in client.chat_completion(
45
  messages,
@@ -57,34 +57,41 @@ demo = gr.ChatInterface(
57
  respond,
58
  additional_inputs=[
59
  gr.Textbox(
60
- value="You are a helpful and friendly AI assistant. Provide informative and accurate responses.",
61
  label="System message"
62
  ),
63
  gr.Slider(
64
  minimum=1,
65
  maximum=2048,
66
- value=512,
67
  step=1,
68
  label="Max new tokens"
69
  ),
70
  gr.Slider(
71
  minimum=0.1,
72
- maximum=2.0,
73
- value=0.7,
74
  step=0.1,
75
  label="Temperature"
76
  ),
77
  gr.Slider(
78
  minimum=0.1,
79
  maximum=1.0,
80
- value=0.95,
81
  step=0.05,
82
  label="Top-p (nucleus sampling)"
83
  ),
84
  ],
85
- title="LLaMA 2 Chatbot",
86
- description="A conversational AI powered by Meta's LLaMA 2 model"
 
 
 
 
 
 
 
87
  )
88
 
89
  if __name__ == "__main__":
90
- demo.launch(share=True) # Added share=True to create a public link
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
+
5
+ # Get your Hugging Face token from environment variables
6
+ HF_Token = os.getenv("HF_TOKEN")
7
+
8
+ # Initialize the inference client with a coding specialized model
9
  client = InferenceClient(
10
+ model="bigcode/starcoder2-15b", # Using StarCoder2 which excels at code generation
11
+ token=HF_Token
12
  )
13
 
14
  def respond(
 
20
  top_p,
21
  ):
22
  """
23
+ Generate coding-focused responses using the selected model.
24
 
25
  Args:
26
  message (str): The current user input message
 
32
  """
33
  # Format the conversation history into messages
34
  messages = [{"role": "system", "content": system_message}]
 
35
  for val in history:
36
  if val[0]:
37
  messages.append({"role": "user", "content": val[0]})
38
  if val[1]:
39
  messages.append({"role": "assistant", "content": val[1]})
 
40
  messages.append({"role": "user", "content": message})
41
+
42
  response = ""
 
43
  # Stream the response tokens
44
  for message in client.chat_completion(
45
  messages,
 
57
  respond,
58
  additional_inputs=[
59
  gr.Textbox(
60
+ value="You are an expert coding assistant. Provide detailed, correct, and efficient code solutions with explanations.",
61
  label="System message"
62
  ),
63
  gr.Slider(
64
  minimum=1,
65
  maximum=2048,
66
+ value=1024,
67
  step=1,
68
  label="Max new tokens"
69
  ),
70
  gr.Slider(
71
  minimum=0.1,
72
+ maximum=1.0,
73
+ value=0.5,
74
  step=0.1,
75
  label="Temperature"
76
  ),
77
  gr.Slider(
78
  minimum=0.1,
79
  maximum=1.0,
80
+ value=0.9,
81
  step=0.05,
82
  label="Top-p (nucleus sampling)"
83
  ),
84
  ],
85
+ title="Coding Expert Assistant",
86
+ description="A specialized coding assistant powered by StarCoder2, a model trained on code repositories",
87
+ examples=[
88
+ "Write a Python function to find the longest palindromic substring",
89
+ "Create a React component that displays a color picker",
90
+ "How do I implement quicksort in JavaScript?",
91
+ "Explain the difference between Promise.all and Promise.allSettled in JavaScript",
92
+ "Generate a Python script to download and process CSV data from an API"
93
+ ]
94
  )
95
 
96
  if __name__ == "__main__":
97
+ demo.launch(share=True)