Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +56 -0
- requirements.txt +8 -0
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain.prompts import PromptTemplate
|
3 |
+
from langchain_community.llms import CTransformers
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
def getLLamaResponse(input_text,no_words,blog_style):
|
8 |
+
|
9 |
+
# LLma Model
|
10 |
+
llm = CTransformers(
|
11 |
+
model="models/llama-2-7b-chat.ggmlv3.q8_0.bin",
|
12 |
+
model_type="llma",
|
13 |
+
config={"max_new_tokens": 256, "temperature": 0.01}
|
14 |
+
)
|
15 |
+
|
16 |
+
# Prompt Template
|
17 |
+
template = """
|
18 |
+
Write a blog for {blog_style} job profile for a topic
|
19 |
+
{input_text} within {no_words} words.
|
20 |
+
"""
|
21 |
+
|
22 |
+
prompt = PromptTemplate(input_variables=["blog_style", "input_text","no_words"],
|
23 |
+
template=template)
|
24 |
+
|
25 |
+
# Generate the response from the LLama 2 Model
|
26 |
+
response = llm(prompt.format(style=blog_style, text=input_text, no_words=no_words))
|
27 |
+
print(response)
|
28 |
+
return response
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
st.set_page_config(page_title = "Generate Blogs",
|
33 |
+
page_icon = "🤖",
|
34 |
+
layout = "centered",
|
35 |
+
initial_sidebar_state = "collapsed")
|
36 |
+
|
37 |
+
st.header("Generate Blogs 🤖")
|
38 |
+
|
39 |
+
input_text = st.text_input("Enter the Blog Topic")
|
40 |
+
|
41 |
+
# Creating 2 more columns for additional 2 fields
|
42 |
+
col1, col2 = st.columns([5,5])
|
43 |
+
|
44 |
+
with col1:
|
45 |
+
no_words = st.text_input("No of words")
|
46 |
+
|
47 |
+
with col2:
|
48 |
+
blog_style=st.selectbox("Writing the blog for",
|
49 |
+
("Researchers","Data Scientist","Common People"),index=0)
|
50 |
+
|
51 |
+
submit = st.button("Generate")
|
52 |
+
|
53 |
+
# Final Response
|
54 |
+
if submit:
|
55 |
+
st.write(getLLamaResponse(input_text,no_words,blog_style))
|
56 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sentence-transformers
|
2 |
+
uvicorn
|
3 |
+
ctransformers
|
4 |
+
fastapi
|
5 |
+
ipykernel
|
6 |
+
langchain
|
7 |
+
python-box
|
8 |
+
streamlit
|