Spaces:
Build error
Build error
| import streamlit as st | |
| from langchain.prompts import PromptTemplate | |
| from langchain_community.llms import CTransformers | |
| from ctransformers import AutoModelForCausalLM | |
| # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system. | |
| llm1 = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-7b-Chat-GGUF", model_file="llama-2-7b-chat.q4_K_M.gguf", model_type="llama", gpu_layers=0) | |
| print(llm("AI is going to")) | |
| def GetLLMResponse(input_text,no_words,blog_type): | |
| llm=llm1 | |
| template=" wtite a blog for {blog_type} on topic of {input_text} in {no_words} words." | |
| prompt=PromptTemplate(input_variables=['blog_type','input_text','no_words'],template=template) | |
| response=llm(prompt.format(blog_type=blog_type,input_text=input_text,no_words=no_words)) | |
| return response | |
| st.set_page_config(page_title="Generative AI Blog", | |
| layout="centered", | |
| initial_sidebar_state='collapsed') | |
| st.header("Blog Generater") | |
| input_text=st.text_input('ENTER THE TOPIC') | |
| col1,col2=st.columns([5,5]) | |
| with col1: | |
| no_words=st.text_input("ENTER THE NUMBER OF WORDS") | |
| with col2: | |
| blog_type=st.selectbox("SELECT BLOG FOR",('SCIENTIST','TEACHER','STUDENT')) | |
| submit=st.button("GENERATE") | |
| if submit: | |
| st.write(GetLLMResponse(input_text,no_words,blog_type)) |