girishwangikar commited on
Commit
433c5a7
·
verified ·
1 Parent(s): b56253f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -44
app.py CHANGED
@@ -7,30 +7,44 @@ GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
7
  client = Groq(api_key=GROQ_API_KEY)
8
 
9
  TITLE = "<h1><center>CodeAssist AI</center></h1>"
10
-
11
- PLACEHOLDER = """
12
- <center>
13
- <p>Hi, I'm your coding assistant. Ask me anything about programming!</p>
14
- </center>
15
- """
16
-
17
  CSS = """
18
- .duplicate-button {
19
- margin: auto !important;
20
- color: white !important;
21
- background: black !important;
22
  border-radius: 100vh !important;
23
  }
24
- h3 {
25
  text-align: center;
26
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  """
28
 
29
  def generate_response(
30
  message: str,
31
- history: list,
32
- system_prompt: str,
33
- temperature: float = 0.7,
34
  max_tokens: int = 512
35
  ):
36
  conversation = [
@@ -38,10 +52,9 @@ def generate_response(
38
  ]
39
  for prompt, answer in history:
40
  conversation.extend([
41
- {"role": "user", "content": prompt},
42
  {"role": "assistant", "content": answer},
43
  ])
44
-
45
  conversation.append({"role": "user", "content": message})
46
 
47
  response = client.chat.completions.create(
@@ -63,38 +76,23 @@ def clear_conversation():
63
 
64
  chatbot = gr.Chatbot(height=600, placeholder=PLACEHOLDER)
65
 
66
- with gr.Blocks(css=CSS, theme="Nymbo/Nymbo_Theme") as demo:
67
  gr.HTML(TITLE)
68
- gr.ChatInterface(
69
  fn=generate_response,
70
  chatbot=chatbot,
71
  fill_height=True,
72
- additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False),
73
- additional_inputs=[
74
- gr.Textbox(
75
- value="You are a helpful coding assistant, specialized in code completion, debugging, and analysis. Provide concise and accurate responses.",
76
- label="System Prompt",
77
- ),
78
- gr.Slider(
79
- minimum=0,
80
- maximum=1,
81
- step=0.1,
82
- value=0.7,
83
- label="Temperature",
84
- ),
85
- gr.Slider(
86
- minimum=50,
87
- maximum=1024,
88
- step=1,
89
- value=512,
90
- label="Max tokens",
91
- ),
92
- ],
93
  examples=[
94
- ["How do I implement a binary search in Python?"],
95
- ["Explain the concept of recursion and provide a simple example."],
96
- ["What are the best practices for error handling in JavaScript?"],
97
- ["How can I optimize this code snippet: [paste your code here]"],
98
  ],
99
  cache_examples=False,
100
  )
@@ -102,5 +100,29 @@ with gr.Blocks(css=CSS, theme="Nymbo/Nymbo_Theme") as demo:
102
  clear_btn = gr.Button("Clear Conversation")
103
  clear_btn.click(clear_conversation, outputs=[chatbot, chatbot])
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  if __name__ == "__main__":
106
  demo.launch()
 
7
  client = Groq(api_key=GROQ_API_KEY)
8
 
9
  TITLE = "<h1><center>CodeAssist AI</center></h1>"
10
+ PLACEHOLDER = """<center><p>Hi, I'm your coding assistant. Ask me anything about programming!</p></center>"""
 
 
 
 
 
 
11
  CSS = """
12
+ .duplicate-button {
13
+ margin: auto !important;
14
+ color: white !important;
15
+ background: purple !important;
16
  border-radius: 100vh !important;
17
  }
18
+ h3 {
19
  text-align: center;
20
  }
21
+ button {
22
+ background-color: purple !important;
23
+ }
24
+ footer {
25
+ text-align: center;
26
+ padding: 10px;
27
+ position: fixed;
28
+ left: 0;
29
+ bottom: 0;
30
+ width: 100%;
31
+ background-color: #f0f0f0;
32
+ }
33
+ """
34
+
35
+ FOOTER_TEXT = """
36
+ <footer>
37
+ <p>If you enjoyed the functionality of the app, please leave a like!<br>
38
+ Check out more on <a href="https://www.linkedin.com/in/girish-wangikar/" target="_blank">LinkedIn</a> |
39
+ <a href="https://girishwangikar.github.io/Girish_Wangikar_Portfolio.github.io/" target="_blank">Portfolio</a></p>
40
+ </footer>
41
  """
42
 
43
  def generate_response(
44
  message: str,
45
+ history: list,
46
+ system_prompt: str,
47
+ temperature: float = 0.5,
48
  max_tokens: int = 512
49
  ):
50
  conversation = [
 
52
  ]
53
  for prompt, answer in history:
54
  conversation.extend([
55
+ {"role": "user", "content": prompt},
56
  {"role": "assistant", "content": answer},
57
  ])
 
58
  conversation.append({"role": "user", "content": message})
59
 
60
  response = client.chat.completions.create(
 
76
 
77
  chatbot = gr.Chatbot(height=600, placeholder=PLACEHOLDER)
78
 
79
+ with gr.Blocks(css=CSS, theme="GSW") as demo:
80
  gr.HTML(TITLE)
81
+ chat_interface = gr.ChatInterface(
82
  fn=generate_response,
83
  chatbot=chatbot,
84
  fill_height=True,
85
+ textbox=gr.Textbox(
86
+ placeholder="Type a message",
87
+ container=False,
88
+ scale=7,
89
+ lines=3
90
+ ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  examples=[
92
+ ["What are Python generators, and how do I use them effectively in my code?"],
93
+ ["Can you explain the different types of SQL joins with examples?"],
94
+ ["How do I calculate the time complexity of a function? Explain with example"],
95
+ ["Explain this code to me: [paste your code here]"],
96
  ],
97
  cache_examples=False,
98
  )
 
100
  clear_btn = gr.Button("Clear Conversation")
101
  clear_btn.click(clear_conversation, outputs=[chatbot, chatbot])
102
 
103
+ with gr.Accordion("⚙️ Parameters", open=False):
104
+ system_prompt = gr.Textbox(
105
+ value="You are a helpful coding assistant, specialized in code completion, debugging, and analysis. Provide concise and accurate responses.",
106
+ label="System Prompt",
107
+ )
108
+ temperature = gr.Slider(
109
+ minimum=0,
110
+ maximum=1,
111
+ step=0.1,
112
+ value=0.7,
113
+ label="Temperature",
114
+ )
115
+ max_tokens = gr.Slider(
116
+ minimum=50,
117
+ maximum=1024,
118
+ step=1,
119
+ value=512,
120
+ label="Max tokens",
121
+ )
122
+
123
+ chat_interface.additional_inputs = [system_prompt, temperature, max_tokens]
124
+
125
+ gr.HTML(FOOTER_TEXT)
126
+
127
  if __name__ == "__main__":
128
  demo.launch()