File size: 1,487 Bytes
4366696
5388181
4366696
 
 
b930ff7
 
 
4366696
 
 
 
 
6c535ba
4366696
 
 
 
b930ff7
4366696
 
 
 
 
 
 
b930ff7
 
 
 
 
 
 
 
 
 
 
 
4366696
 
 
 
 
 
 
 
 
 
 
 
 
 
b930ff7
4366696
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import streamlit as st
from langchain_openai import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from dotenv import load_dotenv
import json
import re


# Load environment variables
load_dotenv()

def getWebsiteLink(company_name):
    llm = OpenAI(temperature=0.0, model="gpt-3.5-turbo-instruct")

    prompt = PromptTemplate(
        input_variables=["company"],
        template="""
        Official website URL of {company} is

        RESPONSE:
        """,
    )

    chain = LLMChain(llm=llm, prompt=prompt)

    response = chain.run(company_name)

    urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', response)

    if urls:  # If any URL is found
        # Take the first URL found (assuming the first URL is the most relevant)
        response_json = json.dumps({"website_link": urls[0]}, indent=4)
    else:
        # If no URL is found, return a "not found" message
        response_json = json.dumps({"website_link": "Not found"}, indent=4)

    return response_json


# UI Starts here
st.set_page_config(page_title="Website URL Generator", page_icon='πŸ”—', layout='centered')

st.header("Website URL Generator")

company_name = st.text_area('Enter the company name', height=150)

submit = st.button("Generate official website")

if submit:
    company_link = getWebsiteLink(company_name)
    st.write("Generate official website:")
    st.code(company_link, language='json')