File size: 2,018 Bytes
7643cf4
82170b9
 
 
 
803e4ae
1f49cbe
559c0e2
803e4ae
 
dd36b8a
7643cf4
82170b9
 
 
 
 
 
 
 
 
 
 
 
7643cf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a998f1
 
7643cf4
 
 
9f6b798
 
 
 
 
473e093
9f6b798
 
 
 
559c0e2
9f6b798
 
7643cf4
 
 
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
56
57
58
59
60
61
62
import streamlit as st
from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate
from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline,BitsAndBytesConfig
import os
from langchain_community.llms import HuggingFaceEndpoint
aa=''

HF_TOKEN = os.environ["HF_TOKEN"]
# quants = BitsAndBytesConfig(load_in_4bit=True)

template = ''' You are an expert Blog generator , Given the Topic , the intended audience and the maximum number of words ,
    Write a blog on the given topic

    Topic : {topic}
    Intended Audince : {role}
    Number of Words : {words}

    Strictly return the output in a markdown format.
    Return only the blog and do not provide any other information.'''


prompt = PromptTemplate(template = template,input_variables = ['topic','role','words'])


def main():
    st.title("	:fire: Professional Blog Generator 	:fire:")
    st.markdown(
        """
        <style>
        body {
            background-color: #000000;;
            color: white;
        }
        </style>
        """,
        unsafe_allow_html=True
    )

    st.sidebar.header("Input Parameters")
    role = st.sidebar.text_input("Who is this intednded for ?", "Data Scientist")
    topic = st.sidebar.text_input("On what Topic should the blog be on ?", "Machine Learning")
    word_count = st.sidebar.slider("Number of Words", min_value=50, max_value=1000, value=200, step=50)

    if st.sidebar.button("Generate Blog"):
        repo_id = "google/gemma-1.1-7b-it"

        llm = HuggingFaceEndpoint(
            repo_id=repo_id, max_length=128, temperature=0.5, huggingfacehub_api_token=HF_TOKEN 
        )
        llm_chain = LLMChain(prompt=prompt, llm=llm)
        # print(llm_chain.run(question))
        aa = llm_chain.run({"topic": topic,"words":word_count,"role":role})
        st.write(aa)
        
    
    # st.write(aa)
    # st.write("Will Come here")

if __name__ == "__main__":
    main()