Ashhar commited on
Commit
5bec612
1 Parent(s): 3eed894

improved image prompt + tuned llama model

Browse files
Files changed (3) hide show
  1. app.py +16 -30
  2. constants.py +2 -1
  3. tools/webScraper.py +10 -7
app.py CHANGED
@@ -128,42 +128,22 @@ def __getRawImagePromptDetails(prompt: str, response: str) -> Tuple[str, str, st
128
  "Painting your character ...",
129
  )
130
 
131
- '''
132
- Style: Fantastical, in a storybook, surreal, bokeh
133
- '''
134
-
135
- '''
136
- Mood: ethereal lighting that emphasizes the fantastical nature of the scene.
137
-
138
- storybook style
139
-
140
- 4d model, unreal engine
141
-
142
- Alejandro Bursido
143
-
144
- vintage, nostalgic
145
-
146
- Dreamlike, Mystical, Fantastical, Charming
147
- '''
148
-
149
  if __matchingKeywordsCount(
150
- ["tier 2", "tier-2"],
151
  cleanedResponse
152
  ) > 0:
153
- possibleStoryEndIdx = [response.find("tier 2"), response.find("tier-2")]
154
- storyEndIdx = max(possibleStoryEndIdx)
155
- relevantResponse = response[:storyEndIdx]
156
- U.pprint(f"{relevantResponse=}")
 
157
  return (
158
- "Extract the story plot from this text:\n{response}",
159
  """
160
  Style: In a storybook, surreal
161
  """,
162
  "Imagining your scene (beta) ...",
163
  )
164
- """
165
- photo of a scene from this text: {relevantResponse}.
166
- """
167
 
168
  return (None, None, None)
169
 
@@ -189,7 +169,13 @@ def __getImagePromptDetails(prompt: str, response: str):
189
  "model": model,
190
  "messages": [{
191
  "role": "user",
192
- "content": f"{promptPrefix} create a prompt for image generation (limit to less than 500 words)\n\n{imagePrompt}"
 
 
 
 
 
 
193
  }],
194
  "temperature": 1,
195
  "max_tokens": 2000
@@ -243,7 +229,7 @@ def predict():
243
  with client.messages.stream(
244
  model=MODEL,
245
  messages=messagesFormatted,
246
- temperature=0.7,
247
  system=C.SYSTEM_MSG,
248
  max_tokens=4000,
249
  ) as stream:
@@ -259,7 +245,7 @@ def predict():
259
  response = client.chat.completions.create(
260
  model=MODEL,
261
  messages=messagesFormatted,
262
- temperature=0.8,
263
  max_tokens=4000,
264
  stream=True
265
  )
 
128
  "Painting your character ...",
129
  )
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  if __matchingKeywordsCount(
132
+ [C.BOOKING_LINK],
133
  cleanedResponse
134
  ) > 0:
135
+ relevantResponse = f"""
136
+ {st.session_state.chatHistory[-1].get("content")}
137
+
138
+ {response}
139
+ """
140
  return (
141
+ f"Extract the story from this text:\n{relevantResponse}",
142
  """
143
  Style: In a storybook, surreal
144
  """,
145
  "Imagining your scene (beta) ...",
146
  )
 
 
 
147
 
148
  return (None, None, None)
149
 
 
169
  "model": model,
170
  "messages": [{
171
  "role": "user",
172
+ "content": f"""
173
+ {promptPrefix} create a prompt for image generation (limit to less than 500 words)
174
+
175
+ {imagePrompt}
176
+
177
+ Return only the final Image Generation Prompt, and nothing else
178
+ """
179
  }],
180
  "temperature": 1,
181
  "max_tokens": 2000
 
229
  with client.messages.stream(
230
  model=MODEL,
231
  messages=messagesFormatted,
232
+ temperature=0.8,
233
  system=C.SYSTEM_MSG,
234
  max_tokens=4000,
235
  ) as stream:
 
245
  response = client.chat.completions.create(
246
  model=MODEL,
247
  messages=messagesFormatted,
248
+ temperature=1,
249
  max_tokens=4000,
250
  stream=True
251
  )
constants.py CHANGED
@@ -1,5 +1,6 @@
1
  JSON_SEPARATOR = ">>>>"
2
  EXCEPTION_KEYWORD = "<<EXCEPTION>>"
 
3
 
4
  SYSTEM_MSG = f"""
5
  => Context:
@@ -104,7 +105,7 @@ If the user has any suggestions, incorporate them and then show the story again.
104
 
105
  ## Tier 2: Story Enhancement
106
  #### After initial story creation, you offer congratulations on completing the first draft and gives 2 options:
107
- Option 1 - Provides option for one-on-one sessions with expert storytelling coaches - the booking can be done that at https://calendly.com/
108
  Option 2 - Provides further options for introducing users to more sophisticated narratives.
109
 
110
  #### If Option 2 chosen, show these options with simple explanation and chose one.
 
1
  JSON_SEPARATOR = ">>>>"
2
  EXCEPTION_KEYWORD = "<<EXCEPTION>>"
3
+ BOOKING_LINK = "https://calendly.com"
4
 
5
  SYSTEM_MSG = f"""
6
  => Context:
 
105
 
106
  ## Tier 2: Story Enhancement
107
  #### After initial story creation, you offer congratulations on completing the first draft and gives 2 options:
108
+ Option 1 - Provides option for one-on-one sessions with expert storytelling coaches - the booking can be done that at {BOOKING_LINK}
109
  Option 2 - Provides further options for introducing users to more sophisticated narratives.
110
 
111
  #### If Option 2 chosen, show these options with simple explanation and chose one.
tools/webScraper.py CHANGED
@@ -4,13 +4,13 @@ import requests
4
 
5
 
6
  def scrapeGoogleSearch(query):
7
- result = []
8
 
9
  searchUrl = f"https://www.google.com/search?q={query}"
10
  response = requests.get(searchUrl)
11
  if response.status_code == 200:
12
  soup = BeautifulSoup(response.text, 'html.parser')
13
- with open('soupDump.html', 'w', encoding='utf-8') as file:
14
  file.write(soup.prettify())
15
 
16
  results = soup.find('body')
@@ -24,11 +24,14 @@ def scrapeGoogleSearch(query):
24
  citationDate = citationDateDiv.text if citationDateDiv else ""
25
  answerText = answerDiv.text.replace(citationDate, '').strip()
26
  citationText = f"Citation Date: {citationDate}" if citationDate else ""
27
- result.append(f"====\n{answerText}\n{citationText}\n====\n\n")
28
 
29
  results = mainDiv.select('div.egMi0.kCrYT')
30
  resultsDesc = mainDiv.select('div.BNeawe.s3v9rd.AP7Wnd .BNeawe.s3v9rd.AP7Wnd:last-child')
31
 
 
 
 
32
  for (i, result) in enumerate(results[:10]):
33
  title = result.find('h3').text
34
  link = result.find('a')['href']
@@ -36,10 +39,10 @@ def scrapeGoogleSearch(query):
36
  urlParams = parse_qs(parsedUrl.query)
37
  link = urlParams.get('q', [None])[0]
38
  desc = resultsDesc[i].text
39
- result.append(f"Title: {title}")
40
- result.append(f"Description: {desc}")
41
- result.append(f"Link: {link}\n")
42
  else:
43
  print("Failed to retrieve search results.")
44
 
45
- return "".join(result)
 
4
 
5
 
6
  def scrapeGoogleSearch(query):
7
+ finalResponse = []
8
 
9
  searchUrl = f"https://www.google.com/search?q={query}"
10
  response = requests.get(searchUrl)
11
  if response.status_code == 200:
12
  soup = BeautifulSoup(response.text, 'html.parser')
13
+ with open('soup_dump.html', 'w', encoding='utf-8') as file:
14
  file.write(soup.prettify())
15
 
16
  results = soup.find('body')
 
24
  citationDate = citationDateDiv.text if citationDateDiv else ""
25
  answerText = answerDiv.text.replace(citationDate, '').strip()
26
  citationText = f"Citation Date: {citationDate}" if citationDate else ""
27
+ finalResponse.append(f"Verified Answer:\n====\n{answerText}\n{citationText}\n====\n\n")
28
 
29
  results = mainDiv.select('div.egMi0.kCrYT')
30
  resultsDesc = mainDiv.select('div.BNeawe.s3v9rd.AP7Wnd .BNeawe.s3v9rd.AP7Wnd:last-child')
31
 
32
+ if results:
33
+ finalResponse.append("Search Results:\n====\n")
34
+
35
  for (i, result) in enumerate(results[:10]):
36
  title = result.find('h3').text
37
  link = result.find('a')['href']
 
39
  urlParams = parse_qs(parsedUrl.query)
40
  link = urlParams.get('q', [None])[0]
41
  desc = resultsDesc[i].text
42
+ finalResponse.append(f"Title: {title}")
43
+ finalResponse.append(f"Description: {desc}")
44
+ finalResponse.append(f"Link: {link}\n")
45
  else:
46
  print("Failed to retrieve search results.")
47
 
48
+ return "\n".join(finalResponse)