Spaces:
Sleeping
Sleeping
gamingflexer
commited on
Commit
·
376cbd6
1
Parent(s):
9ae2835
gradio app added.
Browse files- src/app.py +41 -2
src/app.py
CHANGED
@@ -1,4 +1,37 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def sample_fun(first_image,voice_input, text_input):
|
4 |
return
|
@@ -12,12 +45,18 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.red, seconda
|
|
12 |
submit_button_tab_1 = gr.Button("Start")
|
13 |
|
14 |
with gr.Tab("Search Catalog"):
|
|
|
|
|
15 |
with gr.Row():
|
16 |
embbed_text_search = gr.Textbox(label="Enter Product Name")
|
17 |
submit_button_tab_4 = gr.Button("Start")
|
18 |
-
dataframe_output_tab_4 = gr.Dataframe(headers=['
|
|
|
|
|
|
|
|
|
19 |
|
20 |
submit_button_tab_1.click(fn=sample_fun,inputs=[voice_input,prodcut_id])
|
21 |
-
submit_button_tab_4.click(fn=
|
22 |
|
23 |
demo.launch(server_name="0.0.0.0",server_port=9003)
|
|
|
1 |
import gradio as gr
|
2 |
+
import pymysql
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
def get_total_number_of_products():
|
6 |
+
connection = connect_to_db()
|
7 |
+
cursor = connection.cursor()
|
8 |
+
|
9 |
+
# Execute SQL query to count total number of products
|
10 |
+
sql = "SELECT COUNT(*) AS total_products FROM api_database"
|
11 |
+
cursor.execute(sql)
|
12 |
+
result = cursor.fetchone()
|
13 |
+
total_products = result['total_products']
|
14 |
+
|
15 |
+
connection.close()
|
16 |
+
|
17 |
+
return total_products
|
18 |
+
|
19 |
+
def search_products(search_query):
|
20 |
+
search_query = " " + search_query.lower() + " "
|
21 |
+
connection = connect_to_db()
|
22 |
+
cursor = connection.cursor()
|
23 |
+
sql = """
|
24 |
+
SELECT * FROM api_database
|
25 |
+
WHERE product_name LIKE %s OR description LIKE %s
|
26 |
+
"""
|
27 |
+
cursor.execute(sql, ('%' + search_query + '%', '%' + search_query + '%'))
|
28 |
+
search_results = cursor.fetchall()
|
29 |
+
|
30 |
+
connection.close()
|
31 |
+
search_results_formatted = []
|
32 |
+
for result in search_results:
|
33 |
+
search_results_formatted.append(list(result.values()))
|
34 |
+
return search_results_formatted
|
35 |
|
36 |
def sample_fun(first_image,voice_input, text_input):
|
37 |
return
|
|
|
45 |
submit_button_tab_1 = gr.Button("Start")
|
46 |
|
47 |
with gr.Tab("Search Catalog"):
|
48 |
+
with gr.Row():
|
49 |
+
total_no_of_products = gr.Textbox(value=str(get_total_number_of_products()),label="Total Products")
|
50 |
with gr.Row():
|
51 |
embbed_text_search = gr.Textbox(label="Enter Product Name")
|
52 |
submit_button_tab_4 = gr.Button("Start")
|
53 |
+
dataframe_output_tab_4 = gr.Dataframe(headers=['id', 'barcode', 'brand', 'sub_brand', 'manufactured_by', 'product_name',
|
54 |
+
'weight', 'variant', 'net_content', 'price', 'parent_category',
|
55 |
+
'child_category', 'sub_child_category', 'images_paths', 'description',
|
56 |
+
'quantity', 'promotion_on_the_pack', 'type_of_packaging', 'mrp'])
|
57 |
+
|
58 |
|
59 |
submit_button_tab_1.click(fn=sample_fun,inputs=[voice_input,prodcut_id])
|
60 |
+
submit_button_tab_4.click(fn=search_products,inputs=[embbed_text_search] ,outputs= dataframe_output_tab_4)
|
61 |
|
62 |
demo.launch(server_name="0.0.0.0",server_port=9003)
|