Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,47 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from langchain.prompts import PromptTemplate
|
3 |
-
#from langchain.llms import CTransformers
|
4 |
-
from langchain import HuggingFaceHub
|
5 |
-
|
6 |
-
# Function to get response from Llama 2 model
|
7 |
-
|
8 |
-
def getLlamaresponse(input_text, no_words, blog_style):
|
9 |
-
#llm = CTransformers(model = 'models\llama-2-7b-chat.Q8_0.gguf', model_type = 'llama',config ={'max_new_tokens': 256, 'temperature':0.01})
|
10 |
-
llm = HuggingFaceHub(
|
11 |
-
repo_id='
|
12 |
-
model_kwargs={'max_new_tokens': 256, 'temperature':0.01}
|
13 |
-
)
|
14 |
-
## Prompt Template
|
15 |
-
|
16 |
-
template = """
|
17 |
-
write a blog for {blog_style} job profile for a topic {input_text} within {no_words} words.
|
18 |
-
"""
|
19 |
-
|
20 |
-
prompt = PromptTemplate(input_variables = ['blog_style','input_text', 'no_words'], template = template)
|
21 |
-
|
22 |
-
# Generate Response from llama2
|
23 |
-
response = llm(prompt.format(blog_style = blog_style, input_text= input_text,no_words = no_words))
|
24 |
-
print(response)
|
25 |
-
return(response)
|
26 |
-
|
27 |
-
|
28 |
-
st.set_page_config(page_title="Generate Blogs",
|
29 |
-
page_icon='🤖',
|
30 |
-
layout='centered',
|
31 |
-
initial_sidebar_state='collapsed')
|
32 |
-
|
33 |
-
st.header("Generate Blogs 🤖")
|
34 |
-
|
35 |
-
input_text=st.text_input("Enter the Blog Topic")
|
36 |
-
|
37 |
-
col1,col2 = st.columns([5,5])
|
38 |
-
|
39 |
-
with col1:
|
40 |
-
no_words = st.text_input('No of Words')
|
41 |
-
with col2:
|
42 |
-
blog_style = st.selectbox('Writing the blog for ', ('Researchers','Data Scientists','Common People'), index = 0)
|
43 |
-
|
44 |
-
submit = st.button('Generate')
|
45 |
-
|
46 |
-
if submit:
|
47 |
st.write(getLlamaresponse(input_text, no_words, blog_style))
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain.prompts import PromptTemplate
|
3 |
+
#from langchain.llms import CTransformers
|
4 |
+
from langchain import HuggingFaceHub
|
5 |
+
|
6 |
+
# Function to get response from Llama 2 model
|
7 |
+
|
8 |
+
def getLlamaresponse(input_text, no_words, blog_style):
|
9 |
+
#llm = CTransformers(model = 'models\llama-2-7b-chat.Q8_0.gguf', model_type = 'llama',config ={'max_new_tokens': 256, 'temperature':0.01})
|
10 |
+
llm = HuggingFaceHub(
|
11 |
+
repo_id='meta-llama/Llama-2-7b-hf',
|
12 |
+
model_kwargs={'max_new_tokens': 256, 'temperature':0.01}
|
13 |
+
)
|
14 |
+
## Prompt Template
|
15 |
+
|
16 |
+
template = """
|
17 |
+
write a blog for {blog_style} job profile for a topic {input_text} within {no_words} words.
|
18 |
+
"""
|
19 |
+
|
20 |
+
prompt = PromptTemplate(input_variables = ['blog_style','input_text', 'no_words'], template = template)
|
21 |
+
|
22 |
+
# Generate Response from llama2
|
23 |
+
response = llm(prompt.format(blog_style = blog_style, input_text= input_text,no_words = no_words))
|
24 |
+
print(response)
|
25 |
+
return(response)
|
26 |
+
|
27 |
+
|
28 |
+
st.set_page_config(page_title="Generate Blogs",
|
29 |
+
page_icon='🤖',
|
30 |
+
layout='centered',
|
31 |
+
initial_sidebar_state='collapsed')
|
32 |
+
|
33 |
+
st.header("Generate Blogs 🤖")
|
34 |
+
|
35 |
+
input_text=st.text_input("Enter the Blog Topic")
|
36 |
+
|
37 |
+
col1,col2 = st.columns([5,5])
|
38 |
+
|
39 |
+
with col1:
|
40 |
+
no_words = st.text_input('No of Words')
|
41 |
+
with col2:
|
42 |
+
blog_style = st.selectbox('Writing the blog for ', ('Researchers','Data Scientists','Common People'), index = 0)
|
43 |
+
|
44 |
+
submit = st.button('Generate')
|
45 |
+
|
46 |
+
if submit:
|
47 |
st.write(getLlamaresponse(input_text, no_words, blog_style))
|