themissingCRAM
commited on
Commit
·
3dd7783
1
Parent(s):
3d07ffa
yea
Browse files- app.py +20 -43
- employment.zip +3 -0
app.py
CHANGED
@@ -1,15 +1,16 @@
|
|
1 |
import datetime
|
2 |
import json
|
3 |
-
import
|
4 |
-
|
5 |
import chromadb
|
6 |
import gradio as gr
|
|
|
7 |
import spaces
|
8 |
from chromadb.utils import embedding_functions
|
9 |
from dotenv import load_dotenv
|
10 |
from langchain.docstore.document import Document
|
11 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
12 |
-
from smolagents import Tool, CodeAgent,
|
13 |
from sqlalchemy import (
|
14 |
create_engine,
|
15 |
MetaData,
|
@@ -20,15 +21,14 @@ from sqlalchemy import (
|
|
20 |
insert,
|
21 |
text, Numeric, DateTime, func
|
22 |
)
|
23 |
-
from huggingface_hub import login
|
24 |
-
from Constants import BAKERY_ORDERS_DATA, BAKING_RECIPES, RAG_QUESTION, SQL_QUERY
|
25 |
from transformers import pipeline
|
26 |
-
|
|
|
|
|
27 |
load_dotenv()
|
28 |
# os.system("python -m phoenix.server.main serve")
|
29 |
import numpy as np
|
30 |
import os
|
31 |
-
import base64
|
32 |
|
33 |
|
34 |
# # Get your own keys from https://cloud.langfuse.com
|
@@ -278,26 +278,10 @@ if __name__ == "__main__":
|
|
278 |
return "", []
|
279 |
|
280 |
|
281 |
-
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3-turbo",device_map = 'cuda')
|
282 |
-
|
283 |
-
|
284 |
-
#
|
285 |
-
# def transcribe(audio):
|
286 |
-
# sr, y = audio
|
287 |
-
#
|
288 |
-
# # Convert to mono if stereo
|
289 |
-
# if y.ndim > 1:
|
290 |
-
# y = y.mean(axis=1)
|
291 |
-
#
|
292 |
-
# y = y.astype(np.float32)
|
293 |
-
# y /= np.max(np.abs(y))
|
294 |
-
#
|
295 |
-
# return transcriber({"sampling_rate": sr, "raw": y})["text"]
|
296 |
@spaces.GPU
|
297 |
-
def transcribe(audio_chunk):
|
298 |
if audio_chunk is None:
|
299 |
return ""
|
300 |
-
print('audio_chunk',audio_chunk)
|
301 |
sr, y = audio_chunk
|
302 |
|
303 |
# Convert to mono if stereo
|
@@ -308,28 +292,18 @@ if __name__ == "__main__":
|
|
308 |
y /= np.max(np.abs(y))
|
309 |
|
310 |
time.sleep(2)
|
311 |
-
text2=transcriber({"sampling_rate": sr, "raw": y})["text"]
|
312 |
-
return text2
|
313 |
-
# sr, y = audio_chunk
|
314 |
-
# # Convert to mono if stereo
|
315 |
-
# if y.ndim > 1:
|
316 |
-
# y = y.mean(axis=1)
|
317 |
-
#
|
318 |
-
# y = y.astype(np.float32)
|
319 |
-
# y /= np.max(np.abs(y))
|
320 |
-
#
|
321 |
-
# if stream is not None or stream.shape != []:
|
322 |
-
# stream = np.concatenate([stream, y])
|
323 |
-
# else:
|
324 |
-
# stream = y
|
325 |
-
# return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
|
326 |
|
|
|
|
|
|
|
|
|
|
|
327 |
|
328 |
with gr.Blocks() as b:
|
329 |
# GUI
|
330 |
gr.Markdown("# Bakery shope ordering llm multi agent system")
|
331 |
with gr.Accordion('''
|
332 |
-
open for more description of this space ''',open=False):
|
333 |
gr.Markdown('''
|
334 |
with self correcting text2sql agent for orders and RAG agent for recipes.
|
335 |
using smolagents, gradio, HF Spaces, sqlalchemy,langchain for sematic search, chromadb\n
|
@@ -342,7 +316,8 @@ if __name__ == "__main__":
|
|
342 |
with gr.Accordion("Bakery orders data", open=False):
|
343 |
gr.DataFrame(pl.DataFrame(BAKERY_ORDERS_DATA))
|
344 |
with gr.Accordion("Baking recipes data", open=False):
|
345 |
-
gr.DataFrame(pl.DataFrame(BAKING_RECIPES,schema=['baking recipes']))
|
|
|
346 |
chatbot = gr.Chatbot(type="messages", height=900)
|
347 |
message_box = gr.Textbox(lines=1, label="chat message:")
|
348 |
with gr.Row():
|
@@ -363,7 +338,9 @@ if __name__ == "__main__":
|
|
363 |
mbox_submit_event = message_box.submit(enter_message,
|
364 |
[message_box, chatbot],
|
365 |
[message_box, chatbot])
|
366 |
-
|
|
|
|
|
367 |
outputs=[message_box
|
368 |
])
|
369 |
rag_q_click_event = rag_q_button.click(enter_message,
|
@@ -383,4 +360,4 @@ if __name__ == "__main__":
|
|
383 |
cancels=[reply_button_click_event, rag_q_click_event, sql_q_click_event, combi_click_event,
|
384 |
mbox_submit_event, audio_stream])
|
385 |
|
386 |
-
|
|
|
1 |
import datetime
|
2 |
import json
|
3 |
+
import time
|
4 |
+
|
5 |
import chromadb
|
6 |
import gradio as gr
|
7 |
+
import polars as pl
|
8 |
import spaces
|
9 |
from chromadb.utils import embedding_functions
|
10 |
from dotenv import load_dotenv
|
11 |
from langchain.docstore.document import Document
|
12 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
13 |
+
from smolagents import Tool, CodeAgent, stream_to_gradio, tool, ToolCallingAgent, HfApiModel
|
14 |
from sqlalchemy import (
|
15 |
create_engine,
|
16 |
MetaData,
|
|
|
21 |
insert,
|
22 |
text, Numeric, DateTime, func
|
23 |
)
|
|
|
|
|
24 |
from transformers import pipeline
|
25 |
+
|
26 |
+
from Constants import BAKERY_ORDERS_DATA, BAKING_RECIPES, RAG_QUESTION, SQL_QUERY
|
27 |
+
|
28 |
load_dotenv()
|
29 |
# os.system("python -m phoenix.server.main serve")
|
30 |
import numpy as np
|
31 |
import os
|
|
|
32 |
|
33 |
|
34 |
# # Get your own keys from https://cloud.langfuse.com
|
|
|
278 |
return "", []
|
279 |
|
280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
@spaces.GPU
|
282 |
+
def transcribe(audio_chunk, message):
|
283 |
if audio_chunk is None:
|
284 |
return ""
|
|
|
285 |
sr, y = audio_chunk
|
286 |
|
287 |
# Convert to mono if stereo
|
|
|
292 |
y /= np.max(np.abs(y))
|
293 |
|
294 |
time.sleep(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
+
message = message + " " + transcriber({"sampling_rate": sr, "raw": y})["text"]
|
297 |
+
return message
|
298 |
+
|
299 |
+
|
300 |
+
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3-turbo", device_map='cuda')
|
301 |
|
302 |
with gr.Blocks() as b:
|
303 |
# GUI
|
304 |
gr.Markdown("# Bakery shope ordering llm multi agent system")
|
305 |
with gr.Accordion('''
|
306 |
+
open for more description of this space ''', open=False):
|
307 |
gr.Markdown('''
|
308 |
with self correcting text2sql agent for orders and RAG agent for recipes.
|
309 |
using smolagents, gradio, HF Spaces, sqlalchemy,langchain for sematic search, chromadb\n
|
|
|
316 |
with gr.Accordion("Bakery orders data", open=False):
|
317 |
gr.DataFrame(pl.DataFrame(BAKERY_ORDERS_DATA))
|
318 |
with gr.Accordion("Baking recipes data", open=False):
|
319 |
+
gr.DataFrame(pl.DataFrame(BAKING_RECIPES, schema=['baking recipes']))
|
320 |
+
|
321 |
chatbot = gr.Chatbot(type="messages", height=900)
|
322 |
message_box = gr.Textbox(lines=1, label="chat message:")
|
323 |
with gr.Row():
|
|
|
338 |
mbox_submit_event = message_box.submit(enter_message,
|
339 |
[message_box, chatbot],
|
340 |
[message_box, chatbot])
|
341 |
+
|
342 |
+
audio_stream = audio_interface.change(transcribe, inputs=[audio_interface, message_box
|
343 |
+
],
|
344 |
outputs=[message_box
|
345 |
])
|
346 |
rag_q_click_event = rag_q_button.click(enter_message,
|
|
|
360 |
cancels=[reply_button_click_event, rag_q_click_event, sql_q_click_event, combi_click_event,
|
361 |
mbox_submit_event, audio_stream])
|
362 |
|
363 |
+
b.launch()
|
employment.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:adc3e8999af8e4c83332f62a68b949b75135e4a3c0eb482722d306416bae45f5
|
3 |
+
size 478921
|