Ephraimmm commited on
Commit
3b94d79
·
verified ·
1 Parent(s): 92c7863

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -91
app.py CHANGED
@@ -249,103 +249,17 @@ def stream_pitchdeck(company_name, url):
249
 
250
  import gradio as gr
251
 
252
- def get_links_user_prompt(website):
253
- user_prompt = f"Here is the list of links on the website of {website.url} - "
254
- user_prompt += "please decide which of these are relevant web links for a brochure about the company, respond with the full https URL in JSON format. \
255
- Do not include Terms of Service, Privacy, email links.\n"
256
- user_prompt += "Links (some might be relative links):\n"
257
- user_prompt += "\n".join(website.links)
258
- return user_prompt
259
-
260
- system_prompt = """
261
- You are a business analyst specializing in creating compelling pitch decks from company website content. Respond in markdown.\
262
- Your task is to analyze multiple relevant pages from a company's website and synthesize the information into a concise, \
263
- professional pitch deck that the company can use for business development, investor relations.
264
-
265
- Your pitch deck should be formatted in markdown and include the following sections when information is available:
266
- - Company overview and mission
267
- - Products/services and value proposition
268
- - Target market and customer base
269
- - Company culture and values
270
- - Growth potential and achievements
271
- - Contact information
272
- - End with We are always happy to help you with (list the services again)
273
-
274
- Focus on creating a narrative that highlights the company's strengths, unique positioning, and opportunities for partnership,\
275
- investment. Ensure the content is professional, engaging, and suitable for multiple audiences including potential clients and investors."""
276
-
277
- def get_all_details(url):
278
- result = "Landing page:\n"
279
- result += Website(url).get_contents()
280
- links = get_links(url)
281
- print("Found links:", links)
282
- for link in links.get("links", []):
283
- result += f"\n\n{link.get('type', 'Unknown Type')}\n"
284
- # Ensure the URL is valid before attempting to scrape
285
- if link.get('url') and (link['url'].startswith('http://') or link['url'].startswith('https://')):
286
- try:
287
- result += Website(link["url"]).get_contents()
288
- except Exception as e:
289
- result += f"Could not retrieve content for {link['url']}: {e}\n"
290
- else:
291
- result += f"Invalid URL found: {link.get('url')}\n"
292
- return result
293
-
294
- def get_pitch_user_prompt(company_name, url):
295
- user_prompt = f"You are looking at a company called: {company_name}\n"
296
- user_prompt += f"Here are the contents of its landing page and other relevant pages; use this information to build a short pitch deck for the company, of the company in markdown.\n"
297
- try:
298
- user_prompt += get_all_details(url)
299
- except Exception as e:
300
- user_prompt += f"Error getting website details: {e}\n"
301
- print(f"Error getting website details for {url}: {e}")
302
- # Provide a fallback or stop processing if website cannot be scraped
303
- return "Could not retrieve website details to generate pitch deck."
304
-
305
- user_prompt = user_prompt[:5_000] # Truncate if more than 5,000 characters
306
- return user_prompt
307
-
308
-
309
- def generate_pitch_deck(company_name, url):
310
- if not company_name or not url:
311
- return "Please provide both company name and URL."
312
-
313
- user_prompt = get_pitch_user_prompt(company_name, url)
314
-
315
- if user_prompt == "Could not retrieve website details to generate pitch deck.":
316
- return user_prompt
317
-
318
- try:
319
- response = openai.chat.completions.create(
320
- model=MODEL,
321
- messages=[
322
- {"role": "system", "content": system_prompt},
323
- {"role": "user", "content": user_prompt}
324
- ],
325
- stream=True # Enable streaming for better UX in Gradio
326
- )
327
-
328
- # Stream the response
329
- response = ""
330
- display_handle = display(Markdown(""), display_id=True)
331
- for chunk in stream:
332
- response += chunk.choices[0].delta.content or ''
333
- response = response.replace("```","").replace("markdown", "")
334
- update_display(Markdown(response), display_id=display_handle.display_id) # Yield intermediate results for streaming
335
-
336
- return response # Return the final result
337
- except Exception as e:
338
- return f"An error occurred during OpenAI API call: {e}"
339
-
340
  iface = gr.Interface(
341
- fn=generate_pitch_deck,
342
  inputs=[
343
  gr.Textbox(label="Company Name"),
344
  gr.Textbox(label="Company Website URL")
345
  ],
346
  outputs=gr.Markdown(label="Generated Pitch Deck"),
347
  title="Company Pitch Deck Generator",
348
- description="Enter the company name and website URL to generate a pitch deck based on their website content."
349
  )
350
 
351
- iface.launch()
 
 
249
 
250
  import gradio as gr
251
 
252
+ reate the Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  iface = gr.Interface(
254
+ fn=stream_pitchdeck,
255
  inputs=[
256
  gr.Textbox(label="Company Name"),
257
  gr.Textbox(label="Company Website URL")
258
  ],
259
  outputs=gr.Markdown(label="Generated Pitch Deck"),
260
  title="Company Pitch Deck Generator",
261
+ description="Enter the company name and website URL to generate a pitch deck based on the website content."
262
  )
263
 
264
+ # Launch the Gradio app
265
+ iface.launch(d)