Ankit93 commited on
Commit
bf7287c
·
1 Parent(s): bed9a55

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain.llms import CTransformers
4
+ from langchain import HuggingFaceHub
5
+ import os
6
+
7
+ import warnings
8
+ warnings.filterwarnings('ignore')
9
+ #streamlit run app.py
10
+ def get_llama_response(inputtext,wordcount,blogstyle):
11
+ ### LLama2 Model Calling..
12
+ # llm = CTransformers(model="model/llama-2-7b-chat.ggmlv3.q2_K.bin",
13
+ # model_type='llama',
14
+ # config={'max_new_tokens':256,
15
+ # 'temperature':0.01})
16
+ template = f"""
17
+ Write a Blog for {blogstyle} job profile for a topic {inputtext} within {wordcount} words.
18
+ """
19
+
20
+
21
+ llm_hugg = HuggingFaceHub(repo_id="google/flan-t5-large",model_kwargs={'temperature':0.6, "max_length":64})
22
+ promptTemp = PromptTemplate(input_variables=['blogstyle','inputtext','wordcount'],
23
+ template=template)
24
+ response = llm_hugg(promptTemp.format(blogstyle=blogstyle,inputtext=inputtext,wordcount=wordcount))
25
+
26
+ return response
27
+
28
+
29
+
30
+ st.set_page_config(page_title='Blog Generation',page_icon="🧊",layout="centered",initial_sidebar_state="collapsed")
31
+
32
+ st.header("Generate Blogs")
33
+
34
+ input_text = st.text_input("Enter the Blog Topic")
35
+ col1,col2 = st.columns([5,5])
36
+
37
+ with col1:
38
+ num_words = st.text_input("No Of Words")
39
+ with col2:
40
+ blog_style = st.selectbox("Writing the Blog For," ,("Researchers","Data Scientist","Common People"),index=0)
41
+
42
+ submit =st.button("Generate")
43
+
44
+ if submit:
45
+ st.subheader("The Response is:")
46
+ st.write(get_llama_response(input_text,num_words,blog_style))