CosmickVisions commited on
Commit
b4a07a5
·
verified ·
1 Parent(s): 40da265

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -134,10 +134,10 @@ def generate_response(message, session_id, model_name, history):
134
  response += f"{repo['description']}\n"
135
  response += f"⭐ {repo['stargazers_count']} | 🍴 {repo['forks_count']} | Language: {repo['language'] or 'Not specified'}\n"
136
  response += f"Updated: {repo['updated_at'][:10]}\n\n"
137
- history.append((message, response))
138
  return history
139
  else:
140
- history.append((message, "No GitHub repositories found for your query."))
141
  return history
142
 
143
  # Check if it's a Stack Overflow search
@@ -152,10 +152,10 @@ def generate_response(message, session_id, model_name, history):
152
  if 'tags' in qa and qa['tags']:
153
  response += f"Tags: {', '.join(qa['tags'][:5])}\n"
154
  response += f"Asked: {qa['creation_date']}\n\n"
155
- history.append((message, response))
156
  return history
157
  else:
158
- history.append((message, "No Stack Overflow questions found for your query."))
159
  return history
160
 
161
  # Check if it's a code explanation request
@@ -163,7 +163,7 @@ def generate_response(message, session_id, model_name, history):
163
  if code_match:
164
  code = code_match.group(1).strip()
165
  explanation = explain_code(code)
166
- history.append((message, explanation))
167
  return history
168
 
169
  system_prompt = "You are a technical assistant specializing in software development, programming, and IT topics."
@@ -181,10 +181,10 @@ def generate_response(message, session_id, model_name, history):
181
  max_tokens=1024
182
  )
183
  response = completion.choices[0].message.content
184
- history.append((message, response))
185
  return history
186
  except Exception as e:
187
- history.append((message, f"Error generating response: {str(e)}"))
188
  return history
189
 
190
  # Functions to update PDF viewer
@@ -549,9 +549,18 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
549
 
550
  with gr.Row(elem_classes="container"):
551
  with gr.Column(scale=2, min_width=600):
552
- chatbot = gr.Chatbot(height=500, bubble_full_width=False, show_copy_button=True, elem_classes="chat-container")
 
 
 
 
 
553
  with gr.Row():
554
- msg = gr.Textbox(show_label=False, placeholder="Ask about your document, type /github to search repos, or /stack to search Stack Overflow...", scale=5)
 
 
 
 
555
  send_btn = gr.Button("Send", scale=1)
556
  clear_btn = gr.Button("Clear Conversation")
557
 
@@ -592,9 +601,9 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
592
  ).then(lambda: "", None, [msg])
593
 
594
  clear_btn.click(
595
- lambda: ([], None, "No PDF uploaded yet", {"page_images": [], "total_pages": 0, "total_words": 0}, 0, None, "No PDF uploaded yet"),
596
  None,
597
- [chatbot, current_session_id, pdf_status, pdf_state, page_slider, pdf_image, stats_display]
598
  )
599
 
600
  page_slider.change(
 
134
  response += f"{repo['description']}\n"
135
  response += f"⭐ {repo['stargazers_count']} | 🍴 {repo['forks_count']} | Language: {repo['language'] or 'Not specified'}\n"
136
  response += f"Updated: {repo['updated_at'][:10]}\n\n"
137
+ history.append({"role": "assistant", "content": response})
138
  return history
139
  else:
140
+ history.append({"role": "assistant", "content": "No GitHub repositories found for your query."})
141
  return history
142
 
143
  # Check if it's a Stack Overflow search
 
152
  if 'tags' in qa and qa['tags']:
153
  response += f"Tags: {', '.join(qa['tags'][:5])}\n"
154
  response += f"Asked: {qa['creation_date']}\n\n"
155
+ history.append({"role": "assistant", "content": response})
156
  return history
157
  else:
158
+ history.append({"role": "assistant", "content": "No Stack Overflow questions found for your query."})
159
  return history
160
 
161
  # Check if it's a code explanation request
 
163
  if code_match:
164
  code = code_match.group(1).strip()
165
  explanation = explain_code(code)
166
+ history.append({"role": "assistant", "content": explanation})
167
  return history
168
 
169
  system_prompt = "You are a technical assistant specializing in software development, programming, and IT topics."
 
181
  max_tokens=1024
182
  )
183
  response = completion.choices[0].message.content
184
+ history.append({"role": "assistant", "content": response})
185
  return history
186
  except Exception as e:
187
+ history.append({"role": "assistant", "content": f"Error generating response: {str(e)}"})
188
  return history
189
 
190
  # Functions to update PDF viewer
 
549
 
550
  with gr.Row(elem_classes="container"):
551
  with gr.Column(scale=2, min_width=600):
552
+ chatbot = gr.Chatbot(
553
+ height=500,
554
+ show_copy_button=True,
555
+ elem_classes="chat-container",
556
+ type="messages"
557
+ )
558
  with gr.Row():
559
+ msg = gr.Textbox(
560
+ show_label=False,
561
+ placeholder="Ask about your code, type /github to search repos, or /stack to search Stack Overflow...",
562
+ scale=5
563
+ )
564
  send_btn = gr.Button("Send", scale=1)
565
  clear_btn = gr.Button("Clear Conversation")
566
 
 
601
  ).then(lambda: "", None, [msg])
602
 
603
  clear_btn.click(
604
+ lambda: ([], None, "No file uploaded", {}, None),
605
  None,
606
+ [chatbot, current_session_id, file_status, code_state, code_metrics]
607
  )
608
 
609
  page_slider.change(