Spaces:
Sleeping
Sleeping
Commit
·
6d18d8f
1
Parent(s):
ebf1a93
Upload 2 files
Browse files- app.py +52 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain.prompts import PromptTemplate
|
| 3 |
+
from langchain.llms import CTransformers
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
### Function to get response from the llama model
|
| 7 |
+
|
| 8 |
+
def getLLamaresponse(input_text, no_words, blog_style):
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
#llama Model
|
| 13 |
+
llm = CTransformers(model="models\llama-2-7b-chat.ggmlv3.q8_0.bin",model_type="llama",
|
| 14 |
+
config={"max_new_tokens":256, "temperature":0.01})
|
| 15 |
+
|
| 16 |
+
#Prompt Template
|
| 17 |
+
template="""
|
| 18 |
+
write a blog for {blog_style} job profile for a topic {input_text} within {no_words} words.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
prompt = PromptTemplate(input_variables=['blog_style', 'input_text', 'no_words'], template=template)
|
| 22 |
+
|
| 23 |
+
#Generate the response
|
| 24 |
+
response = llm(prompt.format(blog_style=blog_style, input_text=input_text, no_words=no_words))
|
| 25 |
+
print(response)
|
| 26 |
+
return response
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
st.set_page_config(
|
| 31 |
+
page_title="Blog Generation",
|
| 32 |
+
page_icon="",
|
| 33 |
+
layout="centered",
|
| 34 |
+
initial_sidebar_state="collapsed")
|
| 35 |
+
|
| 36 |
+
st.header("Blog Generation")
|
| 37 |
+
|
| 38 |
+
input_text = st.text_input("Enter the text you want to generate a blog on")
|
| 39 |
+
|
| 40 |
+
## Creating 2 more field
|
| 41 |
+
## 1. Number of words to generate
|
| 42 |
+
## 2. Number of blogs to generate
|
| 43 |
+
col_1, col_2 = st.columns([5,5])
|
| 44 |
+
with col_1:
|
| 45 |
+
num_words = st.number_input("Enter the number of words to generate", min_value=10, max_value=1000, value=100)
|
| 46 |
+
with col_2:
|
| 47 |
+
blog_style = st.selectbox("Select the blog style", ["researchers", "layman", "technical_audience"], index=0)
|
| 48 |
+
|
| 49 |
+
submit = st.button("Generate Blog")
|
| 50 |
+
|
| 51 |
+
if submit:
|
| 52 |
+
st.write(getLLamaresponse(input_text, num_words, blog_style))
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
sentence-transformers
|
| 2 |
+
uvicorn
|
| 3 |
+
streamlit
|
| 4 |
+
langchain
|
| 5 |
+
python-box
|