Spaces:
Sleeping
Sleeping
Ganesh Chintalapati
commited on
Commit
·
128373b
1
Parent(s):
e71d648
Fix TypeError in submit_query and set Chatbot type to messages
Browse files
app.py
CHANGED
@@ -152,7 +152,7 @@ async def ask_gemini(query: str, history: List[Dict[str, str]]) -> str:
|
|
152 |
logger.error(f"Gemini Error: {str(e)}")
|
153 |
return f"Error: Gemini Error: {str(e)}"
|
154 |
|
155 |
-
async def query_model(query: str, provider: str, history: List[Dict[str, str]]) -> Tuple[str, List[Dict[str, str]]]:
|
156 |
provider = provider.lower()
|
157 |
response = ""
|
158 |
|
@@ -174,6 +174,16 @@ async def query_model(query: str, provider: str, history: List[Dict[str, str]])
|
|
174 |
updated_history = history + [{"user": query, "bot": response}]
|
175 |
yield response, updated_history # Final yield with updated history
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
# Gradio interface
|
178 |
def clear_history():
|
179 |
return [], []
|
@@ -184,18 +194,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
184 |
|
185 |
provider = gr.Dropdown(choices=["OpenAI", "Anthropic", "Gemini"], label="Select Provider", value="OpenAI")
|
186 |
history_state = gr.State(value=[])
|
187 |
-
chatbot = gr.Chatbot(label="Conversation")
|
188 |
query = gr.Textbox(label="Enter your query", placeholder="e.g., What is the capital of the United States?")
|
189 |
submit_button = gr.Button("Submit")
|
190 |
clear_button = gr.Button("Clear History")
|
191 |
|
192 |
-
def submit_query(query, provider, history):
|
193 |
-
if not query.strip():
|
194 |
-
return "", history, history
|
195 |
-
for response_chunk, updated_history in query_model(query, provider, history):
|
196 |
-
yield response_chunk, updated_history, updated_history
|
197 |
-
return "", updated_history, updated_history
|
198 |
-
|
199 |
submit_button.click(
|
200 |
fn=submit_query,
|
201 |
inputs=[query, provider, history_state],
|
|
|
152 |
logger.error(f"Gemini Error: {str(e)}")
|
153 |
return f"Error: Gemini Error: {str(e)}"
|
154 |
|
155 |
+
async def query_model(query: str, provider: str, history: List[Dict[str, str]]) -> AsyncGenerator[Tuple[str, List[Dict[str, str]]], None]:
|
156 |
provider = provider.lower()
|
157 |
response = ""
|
158 |
|
|
|
174 |
updated_history = history + [{"user": query, "bot": response}]
|
175 |
yield response, updated_history # Final yield with updated history
|
176 |
|
177 |
+
async def submit_query(query: str, provider: str, history: List[Dict[str, str]]) -> Tuple[str, List[Dict[str, str]], List[Dict[str, str]]]:
|
178 |
+
if not query.strip():
|
179 |
+
return "", history, history
|
180 |
+
|
181 |
+
response = ""
|
182 |
+
async for response_chunk, updated_history in query_model(query, provider, history):
|
183 |
+
response += response_chunk
|
184 |
+
yield "", updated_history, updated_history # Yield intermediate updates for streaming
|
185 |
+
return "", updated_history, updated_history # Final return with cleared query
|
186 |
+
|
187 |
# Gradio interface
|
188 |
def clear_history():
|
189 |
return [], []
|
|
|
194 |
|
195 |
provider = gr.Dropdown(choices=["OpenAI", "Anthropic", "Gemini"], label="Select Provider", value="OpenAI")
|
196 |
history_state = gr.State(value=[])
|
197 |
+
chatbot = gr.Chatbot(label="Conversation", type="messages")
|
198 |
query = gr.Textbox(label="Enter your query", placeholder="e.g., What is the capital of the United States?")
|
199 |
submit_button = gr.Button("Submit")
|
200 |
clear_button = gr.Button("Clear History")
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
submit_button.click(
|
203 |
fn=submit_query,
|
204 |
inputs=[query, provider, history_state],
|