IAMTFRMZA commited on
Commit
95695d7
·
verified ·
1 Parent(s): d292cf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -14
app.py CHANGED
@@ -22,13 +22,11 @@ client = OpenAI(api_key=OPENAI_API_KEY)
22
 
23
  # ------------------ Chat Logic ------------------
24
  session_threads = {}
25
- session_messages = {}
26
 
27
  def reset_session():
28
  session_id = str(uuid.uuid4())
29
  thread = client.beta.threads.create()
30
  session_threads[session_id] = thread.id
31
- session_messages[session_id] = []
32
  return session_id
33
 
34
  def process_chat(message, history, session_id):
@@ -65,13 +63,7 @@ def process_chat(message, history, session_id):
65
  else:
66
  assistant_response = "⚠️ Assistant did not respond."
67
 
68
- # Optional: detect GitHub image URL
69
- image_url = None
70
- match = re.search(r'https://raw\.githubusercontent\.com/AndrewLORTech/surgical-pathology-manual/main/[\w\-/]*\.png', assistant_response)
71
- if match:
72
- image_url = match.group(0)
73
-
74
- return assistant_response, image_url
75
 
76
  # ------------------ Transcription Logic ------------------
77
  def create_websocket_client():
@@ -102,10 +94,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
102
  # ---------- Section 1: Chat Interface ----------
103
  with gr.Row():
104
  chatbot = gr.ChatInterface(
105
- fn=lambda message, history, session_id: (
106
- process_chat(message, history, session_id)[0],
107
- process_chat(message, history, session_id)[1],
108
- ),
109
  additional_inputs=[session_id],
110
  examples=[
111
  ["What does clause 3.2 mean?"],
@@ -121,7 +110,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
121
  transcript_box = gr.Textbox(label="Live Transcript", lines=7, interactive=False, autoscroll=True)
122
 
123
  with gr.Row():
124
- mic_input = gr.Audio(streaming=True) # ✅ FIXED: removed unsupported source="microphone"
125
  clear_button = gr.Button("Clear Transcript")
126
 
127
  mic_input.stream(fn=send_audio_chunk, inputs=[mic_input, client_id], outputs=transcript_box)
 
22
 
23
  # ------------------ Chat Logic ------------------
24
  session_threads = {}
 
25
 
26
  def reset_session():
27
  session_id = str(uuid.uuid4())
28
  thread = client.beta.threads.create()
29
  session_threads[session_id] = thread.id
 
30
  return session_id
31
 
32
  def process_chat(message, history, session_id):
 
63
  else:
64
  assistant_response = "⚠️ Assistant did not respond."
65
 
66
+ return assistant_response # only returning text now
 
 
 
 
 
 
67
 
68
  # ------------------ Transcription Logic ------------------
69
  def create_websocket_client():
 
94
  # ---------- Section 1: Chat Interface ----------
95
  with gr.Row():
96
  chatbot = gr.ChatInterface(
97
+ fn=lambda message, history, session_id: process_chat(message, history, session_id),
 
 
 
98
  additional_inputs=[session_id],
99
  examples=[
100
  ["What does clause 3.2 mean?"],
 
110
  transcript_box = gr.Textbox(label="Live Transcript", lines=7, interactive=False, autoscroll=True)
111
 
112
  with gr.Row():
113
+ mic_input = gr.Audio(streaming=True) # ✅ fixed for Hugging Face compatibility
114
  clear_button = gr.Button("Clear Transcript")
115
 
116
  mic_input.stream(fn=send_audio_chunk, inputs=[mic_input, client_id], outputs=transcript_box)