File size: 2,016 Bytes
8a752b2
 
 
a136895
546eeec
 
ddea6bd
546eeec
 
 
 
8a752b2
546eeec
d8dbe7c
 
8a752b2
 
 
ff78f0b
8a752b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from langchain.llms import CTransformers
from langchain.prompts import PromptTemplate
from transformers import AutoModelForCausalLM, AutoModel
from dotenv import load_dotenv
from huggingface_hub import login
import os
# get environment variables
load_dotenv()
access_token = os.getenv("HUGGINGFACE_TOKEN")
login(token=access_token)

# from transformers import pipeline
model_name = "karthiksagarn/llama-2-7b-chat"
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=access_token, from_tf=True)

## Function to get response form the LLama2 Model
def getLLamaResponse(input_text, no_of_words, blog_style):
    llm = CTransformers(model=model,
                        model_type='llama',
                        config={"max_new_tokens": 256,
                                'temperature': 0.01})
    template = """
        write a blog for {blog_style} job profile for a topic {input_text}
        within {no_of_words} words.
            """
    prompt = PromptTemplate(input_variables=["blog_style", "input_text", "no_of_words"],
                            template=template)
    response = llm(prompt.format(blog_style=blog_style, input_text=input_text, no_of_words=no_of_words))
    st.write(response)
    return response


st.set_page_config(page_title= "Generate Blogs",
                   page_icon="πŸ€–",
                   layout='centered',
                   initial_sidebar_state="collapsed")

st.header("Generate Blogs πŸ€–")

input_text = st.text_input("Enter the Blog Topic")

## creating two columns for additional two fields

col1, col2 = st.columns([5,5])

with col1:
    no_of_words = st.text_input("Enter the No. of words")
with col2:
    blog_style = st.selectbox("writing the blog for",
                              ('Researchers', 'Data Scientists', 'ML Engineers', 'Common People'),
                              index=0)
submit = st.button("Generate")

#final respponse
if submit:
    st.write(getLLamaResponse(input_text, no_of_words, blog_style))