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)