File size: 6,432 Bytes
d050721
 
 
 
13e6d7b
bf28f3c
d050721
 
 
 
bd2410d
d050721
 
 
 
 
bd2410d
13e6d7b
5e65fb9
bd2410d
 
 
 
 
 
 
 
 
d050721
bd2410d
 
d050721
 
 
 
 
 
 
 
bd2410d
 
 
 
 
 
 
 
 
 
 
d050721
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5258fe
f5113a0
d050721
 
 
 
 
 
 
bd2410d
d050721
 
 
 
 
 
 
889ba26
 
 
b390609
d050721
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd2410d
 
076fe2e
 
e056cb6
bd2410d
 
 
d050721
 
 
 
 
076fe2e
bd2410d
d050721
 
e680ea7
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import gradio as gr
from huggingface_hub import InferenceClient
import gradio as gr
import random
import os


checkpoint = "mistralai/Mixtral-8x7B-Instruct-v0.1"
client = InferenceClient(checkpoint)


def format_prompt(raw_Prompt):
    better_prompt = f"[INST] {raw_Prompt} [/INST]"
    return better_prompt


def findShops(target_platform, target_region, target_field, target_rangeFrom, target_rangeTo, target_crossSelling, target_similarArticles, target_amount, accessKey):
    if accessKey != os.environ['ACCESS_TOKEN']:
        return 'You are not authorized to use this software.'
    if target_platform == 'All':
        basePrompt = f"""
        Search for {target_amount} Shops with a website.
        """
    else:
        basePrompt = f"""
        Search for {target_amount} Shops that use the platform {target_platform}.
        """
    regionPrompt = f"""
    Make sure the recommended shops are located in {target_region}.
    """
    rangePrompt = f"""
    The websites of the recommended shops should have between {target_rangeFrom} and {target_rangeTo} monthly visitors."""
    crossSellingPrompt = """
    The recommended shops should be potential customers for a software that improves the cross-selling on their website."""
    similarArticlesPrompt = """
    The recommended shops should be potential customers for a software that can recommend similar products to the customers."""
    fieldPrompt = f"""
    Focus on shops that have a focus on the topic'{target_field}'."""
    stylePrompt = """
    Your response must be a list in markdown format.
    Each element of the list must follow these rules:
    - The title for each element must be the name of the shop.
    - The information coming after the title must each start in a new line.
    - The first information for each element must be a link to the website.
    - The next information must always be the number of monthly website visitors.
    - The next information must always be a summary of what is sold in the shop.
   """
    fullPrompt = basePrompt
    fullPrompt += regionPrompt
    fullPrompt += rangePrompt
    if target_crossSelling:
        fullPrompt += crossSellingPrompt
    if target_similarArticles:
        fullPrompt += similarArticlesPrompt
    if target_field != 'All':
        fullPrompt += fieldPrompt
    fullPrompt += stylePrompt
    generate_kwargs = dict(
        temperature=0.2,
        max_new_tokens=10000,
        top_p=0.9,
        repetition_penalty=1.0,
        do_sample=True,
        seed=random.randint(0, 100000),
    )
    stream = client.text_generation(format_prompt(fullPrompt),
                                    **generate_kwargs,
                                    stream=True,
                                    details=True,
                                    return_full_text=False)
    output = ""
    for response in stream:
        output += response.token.text
    output = output.removesuffix('</s>')
    return output


with gr.Blocks(title="Shop finder",
               theme=gr.themes.Soft(primary_hue="purple")) as demo:
    gr.Markdown(
        "##  Shop finder")
    gr.Markdown(
        "Choose the right settings and click **FIND** to search for shops.")
    with gr.Group():
        gr.Markdown("**FILTERS**")
        with gr.Column():
            platform = gr.Dropdown(choices=['All', 'Shopware', 'Shopify'],
                                   value='Shopware',
                                   interactive=True,
                                   label="PLATFORM")
            region = gr.Dropdown(choices=['Germany', 'England', 'France', 'Italy', 'Austria'],
                                 value='Germany',
                                 interactive=True,
                                 label="REGION")
            field = gr.Dropdown(choices=['All', 'Fashion', 'Outdoor', 'Home & Living',
                                         'Beauty & Cosmetics', 'Luggage & Bags',
                                         'Office & School materials','Pets','Sports',
                                        'Tech','Toys','Jewelry & Accessories','Food'],
                                value='All',
                                interactive=True,
                                label="FIELD")
    with gr.Group():
        gr.Markdown("**MONTHLY VISITORS**")
        with gr.Row():
            range_from = gr.Slider(minimum=0,
                                   maximum=1_000_000,
                                   value=100,
                                   step=100,
                                   label="FROM",
                                   interactive=True)
            range_to = gr.Slider(minimum=0,
                                 maximum=1_000_000,
                                 value=10_000,
                                 step=100,
                                 label="TO",
                                 interactive=True)
    with gr.Group():
        gr.Markdown("**POTENTIAL PRODUCT**")
        with gr.Row():
            opt_crossSelling = gr.Checkbox(value=False,
                                           label='CROSSELLING POTENTIAL',
                                           interactive=True)
            opt_similarArticles = gr.Checkbox(value=False,
                                              label='SIMILARITY POTENTIAL',
                                              interactive=True)
    numberOfShops = gr.Slider(minimum=1,
                              maximum=50,
                              value=10,
                              step=1,
                              label="AMOUNT",
                              interactive=True)

    btn = gr.Button("FIND")
    with gr.Group():
        gr.Markdown("**RESULTS**")
        out = gr.Markdown(value=' <br /> <br /> <br /> <br /> <br /> <br />',
                          label='POTENTIAL SHOPS')
    with gr.Group():
        gr.Markdown("*ACCESS SECRET*")
        loginKey = gr.Textbox(max_lines=1,
                              interactive=True,
                              type='password',
                              show_label=False)
    btn.click(fn=findShops,
              inputs=[platform, region, field,
                      range_from, range_to,
                      opt_crossSelling,
                      opt_similarArticles,
                      numberOfShops,
                      loginKey],
              outputs=out)

demo.launch(show_api=False)