File size: 1,991 Bytes
7643cf4
82170b9
 
 
 
dd36b8a
7643cf4
82170b9
 
 
 
 
 
 
 
 
 
 
 
7643cf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a998f1
 
7643cf4
 
 
31a1f3b
8a998f1
 
82170b9
 
 
 
 
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
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
# 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"):
        model_id = "mistralai/Mistral-7B-Instruct-v0.1"
        tokenizer = AutoTokenizer.from_pretrained(model_id,auth_token =HF_TOKEN )
        model = AutoModelForCausalLM.from_pretrained(model_id,auth_token =HF_TOKEN )
        pipe = pipeline("text-generation", model=model, tokenizer=tokenizer,max_new_tokens=1000)
        hf = HuggingFacePipeline(pipeline=pipe)
        chain = LLMChain(llm=hf,prompt=prompt,verbose=True)
        aa = chain.invoke({"topic": topic,"words":word_count,"role":role})
        st.write(aa)

if __name__ == "__main__":
    main()