Spaces:
Sleeping
Sleeping
Krzysztof Krystian Jankowski
commited on
Commit
•
076a09d
1
Parent(s):
b65bc7e
initial commit
Browse files- app.py +39 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain.prompts import PromptTemplate
|
3 |
+
from langchain_community.llms import CTransformers
|
4 |
+
|
5 |
+
# load the model
|
6 |
+
|
7 |
+
def getLlamaResponse(input_text, no_words, blog_style):
|
8 |
+
llm=CTransformers(model='models/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf',
|
9 |
+
model_type='llama',
|
10 |
+
config={'max_new_tokens':256, 'temperature':0.2})
|
11 |
+
|
12 |
+
# create a prompt
|
13 |
+
|
14 |
+
template="""
|
15 |
+
Write a blog post about the topic: {input_text} in {blog_style} style. The blog should be {no_words} words long.
|
16 |
+
"""
|
17 |
+
prompt=PromptTemplate(input_variables=["blog_style", "input_text", "no_words"],
|
18 |
+
template=template)
|
19 |
+
|
20 |
+
# generate the response
|
21 |
+
response=llm.invoke(prompt.format(blog_style=blog_style, input_text=input_text, no_words=no_words))
|
22 |
+
|
23 |
+
return response
|
24 |
+
|
25 |
+
# Streamlit UI
|
26 |
+
st.set_page_config(page_title="GenBlog Demo",
|
27 |
+
page_icon="📚",
|
28 |
+
layout="centered",
|
29 |
+
initial_sidebar_state='collapsed')
|
30 |
+
st.header("GenBlog Demo 📚")
|
31 |
+
input_text=st.text_input("Enter the Blog Topic")
|
32 |
+
col1, col2 = st.columns([5, 5])
|
33 |
+
with col1:
|
34 |
+
no_words=st.text_input("Enter the number of words", value=100)
|
35 |
+
with col2:
|
36 |
+
blog_style=st.selectbox("Select the Blog Style", ["Personal", "Research", "Story Driven"])
|
37 |
+
submit=st.button("Generate Blog")
|
38 |
+
if submit:
|
39 |
+
st.write(getLlamaResponse(input_text, no_words, blog_style))
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sentence-transformers
|
2 |
+
uvicorn
|
3 |
+
ctransformers
|
4 |
+
langchain
|
5 |
+
langchain-community
|
6 |
+
python-box
|
7 |
+
streamlit
|