Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
import gradio as gr
|
4 |
+
import random
|
5 |
+
|
6 |
+
checkpoint = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
7 |
+
client = InferenceClient(checkpoint)
|
8 |
+
|
9 |
+
|
10 |
+
def format_prompt(raw_Prompt):
|
11 |
+
better_prompt = f"[INST] {raw_Prompt} [/INST]"
|
12 |
+
return better_prompt
|
13 |
+
|
14 |
+
|
15 |
+
def findShops(target_platform, target_region, target_field, target_rangeFrom, target_rangeTo, target_crossSelling, target_similarArticles, target_amount):
|
16 |
+
requestPrompt = f"""
|
17 |
+
Search for {target_amount} Shops that use the platform {target_platform}.
|
18 |
+
Make sure the recommended shops are located in {target_region}.
|
19 |
+
The websites of the recommended shops should have between {target_rangeFrom} and {target_rangeTo} monthly visitors."""
|
20 |
+
crossSellingPrompt = """
|
21 |
+
The recommended shops should be potential customers for a software that improves the cross-selling on their website."""
|
22 |
+
similarArticlesPrompt = """
|
23 |
+
The recommended shops should be potential customers for a software that can recommend similar products to the customers."""
|
24 |
+
fieldPrompt = f"""
|
25 |
+
Focus on shops that have a focus on the topic'{target_field}'."""
|
26 |
+
stylePrompt = """
|
27 |
+
Leave an empty line between your recommendations.
|
28 |
+
Present your results in a list with the names of the shops as the headings."""
|
29 |
+
fullPrompt = requestPrompt
|
30 |
+
if target_crossSelling:
|
31 |
+
fullPrompt += crossSellingPrompt
|
32 |
+
if target_similarArticles:
|
33 |
+
fullPrompt += similarArticlesPrompt
|
34 |
+
if target_field != 'All':
|
35 |
+
fullPrompt += fieldPrompt
|
36 |
+
fullPrompt += stylePrompt
|
37 |
+
generate_kwargs = dict(
|
38 |
+
temperature=0.2,
|
39 |
+
max_new_tokens=10000,
|
40 |
+
top_p=0.9,
|
41 |
+
repetition_penalty=1.0,
|
42 |
+
do_sample=True,
|
43 |
+
seed=random.randint(0, 100000),
|
44 |
+
)
|
45 |
+
stream = client.text_generation(format_prompt(fullPrompt),
|
46 |
+
**generate_kwargs,
|
47 |
+
stream=True,
|
48 |
+
details=True,
|
49 |
+
return_full_text=False)
|
50 |
+
output = ""
|
51 |
+
for response in stream:
|
52 |
+
output += response.token.text
|
53 |
+
output = output.removesuffix('</s>')
|
54 |
+
return output
|
55 |
+
|
56 |
+
|
57 |
+
with gr.Blocks(title="Shop finder",
|
58 |
+
theme=gr.themes.Soft(primary_hue="sky")) as app:
|
59 |
+
gr.Markdown(
|
60 |
+
"## Shop finder")
|
61 |
+
gr.Markdown(
|
62 |
+
"Choose the right settings and click **FIND** to search for shops.")
|
63 |
+
with gr.Group():
|
64 |
+
gr.Markdown("**FILTERS**")
|
65 |
+
with gr.Column():
|
66 |
+
platform = gr.Dropdown(choices=['Shopware', 'Shopify'],
|
67 |
+
value='Shopware',
|
68 |
+
interactive=True,
|
69 |
+
label="PLATFORM")
|
70 |
+
region = gr.Dropdown(choices=['Germany', 'England', 'France', 'Italy', 'Austria'],
|
71 |
+
value='Germany',
|
72 |
+
interactive=True,
|
73 |
+
label="REGION")
|
74 |
+
field = gr.Dropdown(choices=['All', 'Home & Living', 'Clothing', 'Electronics', 'Sports', 'Toys'],
|
75 |
+
value='All',
|
76 |
+
interactive=True,
|
77 |
+
label="FIELD")
|
78 |
+
with gr.Group():
|
79 |
+
gr.Markdown("**MONTHLY VISITORS**")
|
80 |
+
with gr.Row():
|
81 |
+
range_from = gr.Slider(minimum=0,
|
82 |
+
maximum=1_000_000,
|
83 |
+
value=100,
|
84 |
+
step=100,
|
85 |
+
label="FROM",
|
86 |
+
interactive=True)
|
87 |
+
range_to = gr.Slider(minimum=0,
|
88 |
+
maximum=1_000_000,
|
89 |
+
value=10_000,
|
90 |
+
step=100,
|
91 |
+
label="TO",
|
92 |
+
interactive=True)
|
93 |
+
with gr.Group():
|
94 |
+
gr.Markdown("**POTENTIAL PRODUCT**")
|
95 |
+
with gr.Row():
|
96 |
+
opt_crossSelling = gr.Checkbox(value=False,
|
97 |
+
label='CROSSELLING POTENTIAL',
|
98 |
+
interactive=True)
|
99 |
+
opt_similarArticles = gr.Checkbox(value=False,
|
100 |
+
label='SIMILARITY POTENTIAL',
|
101 |
+
interactive=True)
|
102 |
+
numberOfShops = gr.Slider(minimum=1,
|
103 |
+
maximum=50,
|
104 |
+
value=10,
|
105 |
+
step=1,
|
106 |
+
label="AMOUNT",
|
107 |
+
interactive=True)
|
108 |
+
|
109 |
+
btn = gr.Button("FIND")
|
110 |
+
with gr.Group():
|
111 |
+
gr.Markdown("**RESULTS**")
|
112 |
+
out = gr.Textbox(lines=10,
|
113 |
+
max_lines=100,
|
114 |
+
label='POTENTIAL SHOPS')
|
115 |
+
btn.click(fn=findShops,
|
116 |
+
inputs=[platform, region, field,
|
117 |
+
range_from, range_to,
|
118 |
+
opt_crossSelling,
|
119 |
+
opt_similarArticles,
|
120 |
+
numberOfShops],
|
121 |
+
outputs=out)
|
122 |
+
|
123 |
+
app.launch(show_api=False)
|