Spaces:
Build error
Build error
File size: 1,771 Bytes
ea6ebd7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import streamlit as st
from langchain.prompts import PromptTemplate
from langchain.llms import CTransformers
def getLLamaresponse(input_text, no_words, blog_style):
# Initialize the language model with the specified configuration
# Use a pipeline as a high-level helper
from transformers import pipeline
llm = pipeline("text-generation", model="TheBloke/Llama-2-7B-Chat-GGML")
# Define the template for the prompt
template = """
Write a blog in {blog_style} job profile for the topic "{input_text}" within {no_words} words.
"""
# Create the prompt using the template
prompt = PromptTemplate(input_variables=['blog_style', 'input_text', 'no_words'], template=template)
# Format the prompt with the provided parameters
formatted_prompt = prompt.format(blog_style=blog_style, input_text=input_text, no_words=no_words)
# Generate the response using the language model
response = llm(formatted_prompt)
return response
# Configure the Streamlit app
st.set_page_config(page_title="Generate Blog",
layout='centered',
initial_sidebar_state='collapsed')
# App header
st.header("Generate Blog")
# Input for the blog topic
input_text = st.text_input("Enter the blog topic")
# Columns for additional inputs
col1, col2 = st.columns([5, 5])
with col1:
no_words = st.text_input('Number of words')
with col2:
blog_style = st.selectbox('Writing the blog for', ('researchers', 'data scientists', 'common people'), index=0)
# Generate button
submit = st.button("Generate")
# Display the generated response
if submit:
response = getLLamaresponse(input_text, no_words, blog_style)
st.write(response)
|