| import streamlit as st |
| from langchain.prompts import PromptTemplate |
| from langchain.llms import CTransformers |
| from langchain import HuggingFaceHub |
| import os |
| from dotenv import load_dotenv |
|
|
| load_dotenv() |
|
|
| import warnings |
| warnings.filterwarnings('ignore') |
| |
| def get_llama_response(inputtext,wordcount,blogstyle): |
|
|
| template = f""" |
| Write a Blog as a {blogstyle} on {inputtext} within {wordcount} words. |
| """ |
| |
| |
| llm_hugg = HuggingFaceHub(repo_id="google/flan-t5-large",model_kwargs={'temperature':0.6, "max_length":64}) |
| promptTemp = PromptTemplate(input_variables=['blogstyle','inputtext','wordcount'], |
| template=template) |
| response = llm_hugg(promptTemp.format(blogstyle=blogstyle,inputtext=inputtext,wordcount=wordcount)) |
|
|
| return response |
|
|
|
|
|
|
| st.set_page_config(page_title='Blog Generation',page_icon="🧊",layout="centered",initial_sidebar_state="collapsed") |
|
|
| st.header("Generate Blogs") |
|
|
| input_text = st.text_input("Enter the Blog Topic") |
| col1,col2 = st.columns([5,5]) |
|
|
| with col1: |
| num_words = st.text_input("No Of Words") |
| with col2: |
| blog_style = st.selectbox("Writing the Blog For," ,("Researchers","Data Scientist","Common People"),index=0) |
|
|
| submit =st.button("Generate") |
|
|
| if submit: |
| st.subheader("The Response is:") |
| st.write(get_llama_response(input_text,num_words,blog_style)) |
|
|