File size: 2,459 Bytes
ca7de80
376cbd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca7de80
 
 
 
502e4ca
ca7de80
 
502e4ca
 
ca7de80
 
 
 
376cbd6
 
ca7de80
502e4ca
ca7de80
376cbd6
 
 
 
 
ca7de80
502e4ca
376cbd6
ca7de80
502e4ca
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
import gradio as gr
import pymysql
import pandas as pd

def get_total_number_of_products():
    connection = connect_to_db()
    cursor = connection.cursor()

    # Execute SQL query to count total number of products
    sql = "SELECT COUNT(*) AS total_products FROM api_database"
    cursor.execute(sql)
    result = cursor.fetchone()
    total_products = result['total_products']

    connection.close()

    return total_products

def search_products(search_query):
    search_query = " " + search_query.lower() + " "
    connection = connect_to_db()
    cursor = connection.cursor()
    sql = """
        SELECT * FROM api_database 
        WHERE product_name LIKE %s OR description LIKE %s
    """
    cursor.execute(sql, ('%' + search_query + '%', '%' + search_query + '%'))
    search_results = cursor.fetchall()

    connection.close()
    search_results_formatted = []
    for result in search_results:
        search_results_formatted.append(list(result.values()))
    return search_results_formatted

def sample_fun(first_image,voice_input, text_input):
    return

with gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.pink)) as demo:
    
    with gr.Tab("Add Your Image"):
        voice_input = gr.Audio(label="Upload Audio")
        prodcut_id = gr.Textbox(label="Enter Product ID")
        with gr.Row():
            submit_button_tab_1 = gr.Button("Start")

    with gr.Tab("Search Catalog"):
        with gr.Row():
            total_no_of_products = gr.Textbox(value=str(get_total_number_of_products()),label="Total Products")
        with gr.Row():
            embbed_text_search = gr.Textbox(label="Enter Product Name")
            submit_button_tab_4 = gr.Button("Start")
        dataframe_output_tab_4 = gr.Dataframe(headers=['id', 'barcode', 'brand', 'sub_brand', 'manufactured_by', 'product_name', 
                                               'weight', 'variant', 'net_content', 'price', 'parent_category', 
                                               'child_category', 'sub_child_category', 'images_paths', 'description', 
                                               'quantity', 'promotion_on_the_pack', 'type_of_packaging', 'mrp'])


    submit_button_tab_1.click(fn=sample_fun,inputs=[voice_input,prodcut_id])
    submit_button_tab_4.click(fn=search_products,inputs=[embbed_text_search] ,outputs= dataframe_output_tab_4)

demo.launch(server_name="0.0.0.0",server_port=9003)