Spaces:
Sleeping
Sleeping
File size: 5,026 Bytes
2c1b143 fac55ce c5f736c 2c1b143 fac55ce 2c1b143 c5f736c 1336ceb c5f736c 1336ceb c5f736c 1336ceb c5f736c 1336ceb c5f736c 1336ceb c5f736c 1336ceb c5f736c 1336ceb c5f736c 1336ceb c5f736c 1336ceb 2c1b143 1336ceb c5f736c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
import gradio as gr
from ultralytics import YOLO
from typing import List
import time
model = YOLO("yolo11n.pt")
def create_chat_interface():
"""Create a minimal chat interface that mirrors the original structure."""
with gr.Blocks() as demo:
# Match the original chatbot structure
chatbot = gr.Chatbot(
show_label=False,
)
msg = gr.Textbox(
show_label=False,
placeholder="Type your message here..."
)
# Keep all the original state objects
transcript_processor_state = gr.State()
call_id_state = gr.State()
colab_id_state = gr.State()
origin_state = gr.State()
ct_state = gr.State()
turl_state = gr.State()
uid_state = gr.State()
# Keep the streaming functionality
def respond(
message: str,
chat_history: List,
transcript_processor,
cid,
rsid,
origin,
ct,
uid,
):
if not transcript_processor:
bot_message = "Transcript processor not initialized."
chat_history.append((message, bot_message))
return "", chat_history
chat_history.append((message, ""))
# Simulate streaming with a simple loop
for i in range(5):
partial_response = f"Processing... {i+1}/5"
chat_history[-1] = (message, partial_response)
yield "", chat_history
time.sleep(0.3)
# Final response
final_response = f"Processed message: {message}\nWith call_id: {cid}"
chat_history[-1] = (message, final_response)
yield "", chat_history
# Keep the exact same function call structure
msg.submit(
respond,
[
msg,
chatbot,
transcript_processor_state,
call_id_state,
colab_id_state,
origin_state,
ct_state,
uid_state,
],
[msg, chatbot],
)
# Match the original on_app_load function
def on_app_load(request: gr.Request):
# Simplified parameter handling
cid = "test_cid"
rsid = "test_rsid"
origin = "test_origin"
ct = "test_ct"
turl = "test_turl"
uid = "test_uid"
# Create a dummy transcript processor
transcript_processor = {"initialized": True}
# Initialize with welcome message
chatbot_value = [(None, "Welcome to the debug interface")]
return [
chatbot_value,
transcript_processor,
cid,
rsid,
origin,
ct,
turl,
uid,
]
def display_processing_message(chatbot_value):
"""Display the processing message while maintaining state."""
# Create new chatbot value with processing message
new_chatbot_value = [
(None, "Processing... Please wait...")
]
return new_chatbot_value
def stream_initial_analysis(
chatbot_value, transcript_processor, cid, rsid, origin, ct, uid
):
if not transcript_processor:
return chatbot_value
# Simulate streaming with a simple loop
for i in range(3):
# Update the existing message
chatbot_value[0] = (None, f"Initial analysis step {i+1}/3...")
yield chatbot_value
time.sleep(0.5)
# Final message
chatbot_value[0] = (None, "Ready to chat! Call ID: " + cid)
yield chatbot_value
# Keep the exact same load chain
demo.load(
on_app_load,
inputs=None,
outputs=[
chatbot,
transcript_processor_state,
call_id_state,
colab_id_state,
origin_state,
ct_state,
turl_state,
uid_state,
],
).then(
display_processing_message,
inputs=[chatbot],
outputs=[chatbot],
).then(
stream_initial_analysis,
inputs=[
chatbot,
transcript_processor_state,
call_id_state,
colab_id_state,
origin_state,
ct_state,
uid_state,
],
outputs=[chatbot],
)
return demo
# Launch the application
if __name__ == "__main__":
app = create_chat_interface()
app.launch() |