Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,3 +31,69 @@ if st.button("Generate Blog"):
|
|
31 |
st.write(blog_content)
|
32 |
else:
|
33 |
st.error("Please provide both the blog topic and the number of words.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
st.write(blog_content)
|
32 |
else:
|
33 |
st.error("Please provide both the blog topic and the number of words.")
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
import streamlit as st
|
38 |
+
from langchain.prompts import PromptTemplate
|
39 |
+
from langchain_community.llms import CTransformers
|
40 |
+
|
41 |
+
## Function To get response from LLaMA 2 model
|
42 |
+
def getLLamaresponse(input_text, no_words, blog_style):
|
43 |
+
### LLaMA 2 model
|
44 |
+
llm = CTransformers(
|
45 |
+
model='llama-2-7b-chat.ggmlv3.q8_0.bin',
|
46 |
+
model_type='llama',
|
47 |
+
config={'max_new_tokens': 256, 'temperature': 0.01}
|
48 |
+
)
|
49 |
+
|
50 |
+
## Prompt Template
|
51 |
+
template = """
|
52 |
+
Write a blog for {blog_style} job profile for a topic {input_text}
|
53 |
+
within {no_words} words.
|
54 |
+
"""
|
55 |
+
|
56 |
+
prompt = PromptTemplate(
|
57 |
+
input_variables=["blog_style", "input_text", "no_words"],
|
58 |
+
template=template
|
59 |
+
)
|
60 |
+
|
61 |
+
## Generate the response from the LLaMA 2 model
|
62 |
+
response = llm.invoke(prompt.format(blog_style=blog_style, input_text=input_text, no_words=no_words))
|
63 |
+
return response
|
64 |
+
|
65 |
+
def main():
|
66 |
+
st.set_page_config(
|
67 |
+
page_title="Generate Blogs",
|
68 |
+
page_icon='🤖',
|
69 |
+
layout='centered',
|
70 |
+
initial_sidebar_state='collapsed'
|
71 |
+
)
|
72 |
+
|
73 |
+
st.header("Generate Blogs 🤖")
|
74 |
+
|
75 |
+
input_text = st.text_input("Enter the Blog Topic")
|
76 |
+
|
77 |
+
## Creating two more columns for additional fields
|
78 |
+
col1, col2 = st.columns([5, 5])
|
79 |
+
|
80 |
+
with col1:
|
81 |
+
no_words = st.text_input('Number of Words')
|
82 |
+
with col2:
|
83 |
+
blog_style = st.selectbox('Writing the blog for', ('Researchers', 'Data Scientist', 'Common People'), index=0)
|
84 |
+
|
85 |
+
submit = st.button("Generate")
|
86 |
+
|
87 |
+
## Final response
|
88 |
+
if submit:
|
89 |
+
if not input_text or not no_words:
|
90 |
+
st.error("Please enter both the blog topic and the number of words.")
|
91 |
+
else:
|
92 |
+
try:
|
93 |
+
response = getLLamaresponse(input_text, no_words, blog_style)
|
94 |
+
st.write(response)
|
95 |
+
except Exception as e:
|
96 |
+
st.error(f"An error occurred: {e}")
|
97 |
+
|
98 |
+
if __name__ == "__main__":
|
99 |
+
main()
|