Cyren4 commited on
Commit
a092d0c
·
1 Parent(s): f304e7d

Upload lafayettegenai.py

Browse files
Files changed (1) hide show
  1. lafayettegenai.py +121 -0
lafayettegenai.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """LafayetteGenAI.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1O5YnxQMF-nf0f4vvP1LazMpb0lVSUxC7?resourcekey=0-7_QS7W_G7BMbC4Uu66z1Dw
8
+ """
9
+
10
+ !pip install -q gradio git+https://github.com/huggingface/transformers gradio torch
11
+
12
+ !pip install google-cloud-aiplatform --upgrade --user
13
+
14
+ # # Automatically restart kernel after installs so that your environment can access the new packages
15
+ import IPython
16
+
17
+ app = IPython.Application.instance()
18
+ app.kernel.do_shutdown(True)
19
+
20
+ from google.colab import auth
21
+ auth.authenticate_user()
22
+
23
+ import vertexai
24
+
25
+ PROJECT_ID = "cloud-llm-preview1" # @param {type:"string"}
26
+ vertexai.init(project=PROJECT_ID, location="us-central1")
27
+
28
+ import pandas as pd
29
+ import seaborn as sns
30
+ from IPython.display import Markdown, display
31
+ from sklearn.metrics.pairwise import cosine_similarity
32
+ from vertexai.preview.language_models import (ChatModel, InputOutputTextPair,
33
+ TextEmbeddingModel,
34
+ TextGenerationModel)
35
+
36
+ generation_model = TextGenerationModel.from_pretrained("text-bison@001")
37
+
38
+ my_industry = "fashion" # try changing this to a different industry
39
+
40
+ response = generation_model.predict(
41
+ prompt=f"What are the top 10 trends in the {my_industry} industry?",
42
+ max_output_tokens=400,
43
+ temperature=0.9,
44
+ top_k=top_k_val,
45
+ )
46
+
47
+ print(response.text)
48
+
49
+ prompt_top_k_example = "Write a 2-day itinerary for France."
50
+ top_k_val = 40
51
+ response = generation_model.predict(
52
+ prompt=prompt_top_k_example,
53
+ max_output_tokens=300,
54
+ temperature=0.9,
55
+ top_k=top_k_val,
56
+ )
57
+ print(response.text)
58
+
59
+ import gradio as gr
60
+
61
+ # Generate a marketing campaign for summer sales named '3J' in march 2023. For Twitter, facebook and instagram
62
+ def generator(title, content, creativity, channels, locations):
63
+ """Generate a marketing campaign for a given industry."""
64
+ temp = creativity/10
65
+
66
+ if not title:
67
+ title = generation_model.predict("Generate maketing campaign title for Gallery Lafayette for " + content, temperature=temp, max_output_tokens=200, top_k=40, top_p=0.8).text
68
+ if "All" in locations :
69
+ locations = ["France"]
70
+
71
+ prompt = f"""Generate a Marketing posts for Gallerie Lafayette {content}. The title will be {title} and adapted to {channels}.""" + \
72
+ f""" It will be for all shops in {" and ".join(locations)}. The campaing will be {"super creative" if creativity > 5 else "entertaining"}"""
73
+
74
+ result = generation_model.predict(prompt, temperature=0.2, max_output_tokens=1024, top_k=40, top_p=0.8).text
75
+ # return f"""The New marketing Campaign will apply to {" and ".join(locations)} and will be shared on {" and ".join(channels)}. It {"already has a title" if title else "doesn't have a title"} and will be {"super creative" if creativity > 5 else "will be standard"}"""
76
+ return result
77
+
78
+ demo1 = gr.Interface(
79
+ generator,
80
+ [
81
+ gr.Textbox(label="Enter your campaign title", info="Leave blank if you don't have one"),
82
+ gr.Textbox(label="Enter campaign brief", info="Core elements"),
83
+ gr.Slider(1, 10, value=4, label="Creativity of your campaign", info="Choose between 1 and 10"),
84
+ gr.Dropdown(
85
+ ["Twitter", "Instagram", "Facebook", "Google Ads", "Website"], label="Pick your communication platforms", info="Adviced to pick one at a time for better result"
86
+ ),
87
+ gr.CheckboxGroup(["Paris", "Lyon", "Besancon", "Marseille", "All"], label="Pick the cities it apply"),
88
+ ],
89
+ # "text",
90
+ outputs=gr.outputs.Textbox(label="Generated campaign"),
91
+ examples=[
92
+ ["Les 3J", "March 2023 sales up to 30% for clothes, shoes, bags.", 10, ["Twitter"], ["Paris", "Marseille"]],
93
+ ["Christmas Special", "Winter 2023 sales up to 40% on all products.", 1, ["Website"], ["All"]],
94
+ ["Father's day", "Get an original gift for father's day among our special selections", 4, ["Facebook"], ["Lyon"]],
95
+ ]
96
+ )
97
+
98
+ def summarizer(content):
99
+ prompt = "Provide a summary with about two sentences for the following article: " + content
100
+ result = generation_model.predict(prompt, temperature=0.2, max_output_tokens=1024, top_k=40, top_p=0.8).text
101
+ return result
102
+
103
+ demo2 = gr.Interface(
104
+ summarizer,
105
+ gr.Textbox(label="Enter your full text:"),
106
+ outputs=gr.outputs.Textbox(label="Summarized content"),
107
+ examples=[
108
+ """The fashion industry has a very big impact on how people dress or see themselves. They use advertisements to try to show the public eye how they should. As time goes on the fashion industry is slowly changing. Hannah Berry's article "The Fashion Industry: Free to Be an Individual" addresses how for many years advertisements try to tell women that they have to use certain things or look a certain way to be attractive but now in modern day time the ads are changing to encourage women to be themselves and wear what they feel expresses them. She goes over two shoes ads that both encourage being yourself. Her article reflects the new found light in the fashion industry as now it tries to uplift women an inspire them to have confidence with themselves and to dress the way they want to dress; and look the way the way they want to look. """,
109
+ "The iconic Galeries Lafayette dates from the late nineteenth century, and has become a genuine symbol of the “City of Light”, visited by over twenty-five million people each year. Its magnificently domed central hall – which covers 70,000 square metres (over three quarters of a million square feet) of retail space – fills an entire block of Boulevard Haussmann, one of several Parisian boulevards built by Napoleon. It’s in the 9th arrondissement, and the celebrated novelist Marcel Proust lived just down the road for many years. he raison d’être of Galeries Lafayette has always been to bring innovation and fashion together in the same space, and make them as widely visible and accessible as possible. To this end – and, frankly, to cock a snook at the competition – Théophile Bader took the decision to make high fashion affordable to all budgets, acquiring production capacity to produce his own fashion brand. He produced articles at the leading edge of fashion, but sold them much more affordably than his competitors.Doing this killed two birds with one stone. Access to fashion was democratised: no longer just for the wealthy few; and the store became wildly popular. To this day,efforts continue constantly to diversify its offering, which now includes men’s clothing, interior decoration, toys and tableware. The business works hard to retain as many shoppers as possible, through annual meetings with customers and strategies such as the well-known “3J” sale, created in 1958 to make excellent items of quality available at exceptionally low prices.",
110
+ """In 1969, a new shop for younger clients opened its doors on the other side of rue Mogador. “Club 20” carried cutting-edge fashion, music and drugstore products. In time, departments were added for men’s fashion and “Lafayette Gourmet”. In 1984 the main hall was completely reorganised to contain a variety of smaller boutique stores in the one space.
111
+
112
+ 2001 was a watershed year for the Lafayette brand, with a massive advertising campaign under the banner of “The Adventures of Laetitia Casta in Galeries Lafayette country”. This campaign had very broad reach both to Parisians and to incoming tourists. It was innovative, modern and offbeat, perfectly capturing the values, history and “spirit” of the store through a variety of images. The imaginative use of mannequins pioneered in this campaign continues to this day.
113
+
114
+ The store also hosts prestigious events with major artists and designers. In order to strengthen and broaden the relationship between Lafayette and fashion, as well as other creative fields, the store opened the “Galerie des Galeries” – a space on the first floor freely accessible to everyone which highlights and explores the links between fashion, art and design.""",
115
+ ]
116
+ )
117
+
118
+ if __name__ == "__main__":
119
+ demo = gr.TabbedInterface([demo1, demo2], ["Marketing Generator", "Summarizer"])
120
+ demo.launch(share=True)
121
+