Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import sqlite3
|
|
| 8 |
import datetime
|
| 9 |
import difflib
|
| 10 |
import logging
|
|
|
|
| 11 |
from tiktoken import get_encoding
|
| 12 |
from openai import AzureOpenAI
|
| 13 |
import httpx
|
|
@@ -362,7 +363,11 @@ async def chat_submit(user_input, chat_history, preprompt):
|
|
| 362 |
|
| 363 |
def get_history():
|
| 364 |
memory = ConversationMemory()
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
|
| 367 |
def get_logs():
|
| 368 |
try:
|
|
@@ -375,8 +380,8 @@ def get_logs():
|
|
| 375 |
return f"Error reading logs: {str(e)}"
|
| 376 |
|
| 377 |
def select_chunk(evt: gr.SelectData):
|
| 378 |
-
logger.info(f"Selected chunk: {evt.value[
|
| 379 |
-
return evt.value[
|
| 380 |
|
| 381 |
async def edit_cut(chunk_id, start, end):
|
| 382 |
api = OpenAIApi(api_key=os.getenv("AZURE_OPENAI_API_KEY"))
|
|
@@ -423,7 +428,8 @@ def create_ui():
|
|
| 423 |
history = gr.Dataframe(
|
| 424 |
label="Recent Chunks",
|
| 425 |
headers=["chunk_id", "text", "role", "timestamp", "intent", "token_count"],
|
| 426 |
-
datatype=["str", "str", "str", "str", "str", "number"]
|
|
|
|
| 427 |
)
|
| 428 |
history_btn = gr.Button("Refresh History")
|
| 429 |
history_btn.click(fn=get_history, outputs=history)
|
|
|
|
| 8 |
import datetime
|
| 9 |
import difflib
|
| 10 |
import logging
|
| 11 |
+
import pandas as pd
|
| 12 |
from tiktoken import get_encoding
|
| 13 |
from openai import AzureOpenAI
|
| 14 |
import httpx
|
|
|
|
| 363 |
|
| 364 |
def get_history():
|
| 365 |
memory = ConversationMemory()
|
| 366 |
+
chunks = memory.get_recent_chunks(limit=10)
|
| 367 |
+
# Convert to list of lists for Gradio Dataframe
|
| 368 |
+
data = [[chunk["chunk_id"], chunk["text"], chunk["role"], chunk["timestamp"], chunk["intent"], chunk["token_count"]] for chunk in chunks]
|
| 369 |
+
logger.info(f"Returning {len(data)} chunks for history: {json.dumps(data, ensure_ascii=False)}")
|
| 370 |
+
return data
|
| 371 |
|
| 372 |
def get_logs():
|
| 373 |
try:
|
|
|
|
| 380 |
return f"Error reading logs: {str(e)}"
|
| 381 |
|
| 382 |
def select_chunk(evt: gr.SelectData):
|
| 383 |
+
logger.info(f"Selected chunk: {evt.value[0]}")
|
| 384 |
+
return evt.value[0], evt.value[1]
|
| 385 |
|
| 386 |
async def edit_cut(chunk_id, start, end):
|
| 387 |
api = OpenAIApi(api_key=os.getenv("AZURE_OPENAI_API_KEY"))
|
|
|
|
| 428 |
history = gr.Dataframe(
|
| 429 |
label="Recent Chunks",
|
| 430 |
headers=["chunk_id", "text", "role", "timestamp", "intent", "token_count"],
|
| 431 |
+
datatype=["str", "str", "str", "str", "str", "number"],
|
| 432 |
+
interactive=False
|
| 433 |
)
|
| 434 |
history_btn = gr.Button("Refresh History")
|
| 435 |
history_btn.click(fn=get_history, outputs=history)
|