mackenzietechdocs commited on
Commit
c155b65
·
1 Parent(s): 1dd1b57

Upgrade to Gradio 6.0.2 with messages format

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +10 -11
  3. requirements.txt +2 -1
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🚀
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 4.44.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 6.0.2
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -8,7 +8,7 @@ An elegant, AI-powered documentation assistant with advanced features.
8
  import os
9
  import gradio as gr
10
  from pathlib import Path
11
- from typing import List, Tuple, Optional
12
  from anthropic import Anthropic
13
  from dotenv import load_dotenv
14
  from document_intelligence import DocumentIntelligence
@@ -81,7 +81,7 @@ def get_available_files() -> List[str]:
81
  return sorted(files)
82
 
83
 
84
- def chat_with_docs(message: str, history: List, system_prompt: str = None) -> str:
85
  """Process user message and generate AI response."""
86
  if not ANTHROPIC_API_KEY:
87
  return "⚠️ Please set your ANTHROPIC_API_KEY in the .env file."
@@ -89,14 +89,11 @@ def chat_with_docs(message: str, history: List, system_prompt: str = None) -> st
89
  # Load documentation context
90
  docs_context = load_documentation()
91
 
92
- # Build conversation history from tuple format
93
  messages = []
94
- for chat_item in history:
95
- if isinstance(chat_item, tuple) and len(chat_item) == 2:
96
- user_msg, assistant_msg = chat_item
97
- messages.append({"role": "user", "content": user_msg})
98
- if assistant_msg:
99
- messages.append({"role": "assistant", "content": assistant_msg})
100
 
101
  messages.append({"role": "user", "content": message})
102
 
@@ -558,7 +555,8 @@ with demo:
558
 
559
  chatbot = gr.Chatbot(
560
  height=550,
561
- show_label=False
 
562
  )
563
 
564
  with gr.Row():
@@ -707,7 +705,8 @@ with demo:
707
  return "", chat_history
708
 
709
  response = chat_with_docs(message, chat_history, system_prompt if system_prompt.strip() else None)
710
- chat_history.append((message, response))
 
711
  return "", chat_history
712
 
713
  msg.submit(respond, [msg, chatbot, custom_system_prompt], [msg, chatbot])
 
8
  import os
9
  import gradio as gr
10
  from pathlib import Path
11
+ from typing import List, Dict, Optional
12
  from anthropic import Anthropic
13
  from dotenv import load_dotenv
14
  from document_intelligence import DocumentIntelligence
 
81
  return sorted(files)
82
 
83
 
84
+ def chat_with_docs(message: str, history: List[dict], system_prompt: str = None) -> str:
85
  """Process user message and generate AI response."""
86
  if not ANTHROPIC_API_KEY:
87
  return "⚠️ Please set your ANTHROPIC_API_KEY in the .env file."
 
89
  # Load documentation context
90
  docs_context = load_documentation()
91
 
92
+ # Build conversation history from messages format
93
  messages = []
94
+ for msg in history:
95
+ if msg.get("role") in ["user", "assistant"]:
96
+ messages.append({"role": msg["role"], "content": msg["content"]})
 
 
 
97
 
98
  messages.append({"role": "user", "content": message})
99
 
 
555
 
556
  chatbot = gr.Chatbot(
557
  height=550,
558
+ show_label=False,
559
+ type="messages"
560
  )
561
 
562
  with gr.Row():
 
705
  return "", chat_history
706
 
707
  response = chat_with_docs(message, chat_history, system_prompt if system_prompt.strip() else None)
708
+ chat_history.append({"role": "user", "content": message})
709
+ chat_history.append({"role": "assistant", "content": response})
710
  return "", chat_history
711
 
712
  msg.submit(respond, [msg, chatbot, custom_system_prompt], [msg, chatbot])
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  mcp[cli]>=0.1.0
2
  anthropic>=0.36.0
3
  python-dotenv>=1.0.1
4
- gradio==4.44.1
 
5
  PyPDF2>=3.0.0
 
1
  mcp[cli]>=0.1.0
2
  anthropic>=0.36.0
3
  python-dotenv>=1.0.1
4
+ gradio==6.0.2
5
+ huggingface-hub>=0.26.0
6
  PyPDF2>=3.0.0