ShopFinder / app.py
Ctaake's picture
Update app.py
e680ea7 verified
raw
history blame
5.16 kB
import gradio as gr
from huggingface_hub import InferenceClient
import gradio as gr
import random
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):
requestPrompt = f"""
Search for {target_amount} Shops that use the platform {target_platform}.
Make sure the recommended shops are located in {target_region}.
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 = """
Leave an empty line between your recommendations.
Present your results in a list with the names of the shops as the headings."""
fullPrompt = requestPrompt
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
demo = gr.Blocks(title="Shop finder",
theme=gr.themes.Soft(primary_hue="sky")) as app:
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=['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', 'Home & Living', 'Clothing', 'Electronics', 'Sports', 'Toys'],
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.Textbox(lines=10,
max_lines=100,
label='POTENTIAL SHOPS')
btn.click(fn=findShops,
inputs=[platform, region, field,
range_from, range_to,
opt_crossSelling,
opt_similarArticles,
numberOfShops],
outputs=out)
demo.launch(show_api=False)