File size: 2,068 Bytes
78489d3
fa73e07
78489d3
 
fa73e07
 
 
 
 
 
78489d3
 
 
 
f36ba97
78489d3
 
 
 
 
 
 
 
 
 
 
 
5b4a01e
 
 
 
78489d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import subprocess
from finetuned import get_search_query
from scraper_script import scrape_flipkart_products

with open('requirements.txt', 'r') as f:
    packages = f.read().splitlines()
for package in packages:
    subprocess.run(['pip', 'install', package])

from itertools import islice
from trends import get_trending_brands
with gr.Blocks() as demo:
    chatbot = gr.Chatbot().style(height=750)
    msg = gr.Textbox(label="Prompt", placeholder="Talk to me here! For example \"I\'m looking for a formal shirt to wear to my interview\" ")
    clear = gr.ClearButton([msg, chatbot])

    def respond(message, chat_history):
        search_query = get_search_query(message).split('\n', 1)[0].strip()
        print(search_query)
        user_info = {
            'name': 'John Doe',
            'gender': 'Male',
            'age': 34,
            'location': 'Hyderabad'
        }

        try:
            popular_brands = get_trending_brands()[:5]
        except:
            popular_brands
        # popular_brands = ['Nike', 'Jockey']
        scraped_results = scrape_flipkart_products(search_query, user_info, popular_brands)

        if(len(scraped_results) == 0):
            bot_message = "I'm sorry, I couldn't find anything."
        else:
            bot_message = "## Understood! Here are my recommendations:\n\n"
            for entry in islice(scraped_results, 3):
                bot_message += f"![Product Image]({entry['Image']})  \n"
                if(entry['Brand']!='N/A'):
                     bot_message += f"**Brand:** {entry['Brand']}  \n"
                bot_message += f"**Description:** {entry['Description']}  \n"
                bot_message += f"**Price:** {entry['Price']}  \n"
                bot_message += f"**Deliver By:** {entry['Delivery_Date']}  \n"
                bot_message += f"**Link:** <a href='{entry['Link']}' target='_blank'>Link</a> \n"


        chat_history.append((message, bot_message))
        return "", chat_history

    msg.submit(respond, [msg, chatbot], [msg, chatbot])


demo.launch()