Spaces:
Sleeping
Sleeping
Commit
•
82170b9
1
Parent(s):
bf11484
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,22 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
|
|
|
|
|
|
|
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
|
6 |
def main():
|
@@ -23,8 +39,14 @@ def main():
|
|
23 |
word_count = st.sidebar.slider("Number of Words", min_value=50, max_value=1000, value=200, step=50)
|
24 |
|
25 |
if st.sidebar.button("Generate Blog"):
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
if __name__ == "__main__":
|
30 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
+
from langchain.chains import LLMChain
|
3 |
+
from langchain_core.prompts import PromptTemplate
|
4 |
+
from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
|
5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline,BitsAndBytesConfig
|
6 |
+
quants = BitsAndBytesConfig(load_in_4bit=True)
|
7 |
|
8 |
+
template = ''' You are an expert Blog generator , Given the Topic , the intended audience and the maximum number of words ,
|
9 |
+
Write a blog on the given topic
|
10 |
+
|
11 |
+
Topic : {topic}
|
12 |
+
Intended Audince : {role}
|
13 |
+
Number of Words : {words}
|
14 |
+
|
15 |
+
Strictly return the output in a markdown format.
|
16 |
+
Return only the blog and do not provide any other information.'''
|
17 |
+
|
18 |
+
|
19 |
+
prompt = PromptTemplate(template = template,input_variables = ['topic','role','words'])
|
20 |
|
21 |
|
22 |
def main():
|
|
|
39 |
word_count = st.sidebar.slider("Number of Words", min_value=50, max_value=1000, value=200, step=50)
|
40 |
|
41 |
if st.sidebar.button("Generate Blog"):
|
42 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.2"
|
43 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id,quantization_config=quants)
|
44 |
+
model = AutoModelForCausalLM.from_pretrained(model_id,quantization_config=quants)
|
45 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer,max_new_tokens=1000)
|
46 |
+
hf = HuggingFacePipeline(pipeline=pipe)
|
47 |
+
chain = LLMChain(llm=hf,prompt=prompt,verbose=True)
|
48 |
+
aa = chain.invoke({"topic": topic,"words":word_count,"role":role})
|
49 |
+
st.write(aa)
|
50 |
|
51 |
if __name__ == "__main__":
|
52 |
main()
|