From 2aa1be734af947506251cb930acbca4629000114 Mon Sep 17 00:00:00 2001 From: FurkanC4 Date: Tue, 17 Sep 2024 10:33:59 +0300 Subject: [PATCH] I added using Local LLM using wtih streamlit. I share the model link. --- README.md | 3 ++- pages/local-LLm.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 pages/local-LLm.py diff --git a/README.md b/README.md index 03030f229..b45268d93 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Current examples include: - LangChain Quickstart - LangChain PromptTemplate - Chat with user feedback - +- local-LLm (Firstly download the model from HuggingFace, dont need API key) + https://huggingface.co/BashitAli/llama-2-7b-chat.ggmlv3.q5_K_M ## Demo App [![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://llm-examples.streamlit.app/) diff --git a/pages/local-LLm.py b/pages/local-LLm.py new file mode 100644 index 000000000..28f405ee0 --- /dev/null +++ b/pages/local-LLm.py @@ -0,0 +1,46 @@ +import streamlit as st +from langchain.prompts import PromptTemplate +from langchain.llms import CTransformers + + + +def getLlamaResponse(input_text, no_words, category): + llm = CTransformers(model = 'model/path', + model_type = 'model_type', # using llama from share link + config={'max_new_tokens': 256, + 'temperature': 0.01}) + + + template = """Write a {category} on {input_text} in less than {no_words} word""" + + prompt = PromptTemplate(input_variables = ["input_text", "no_words", "category"], + template = template) + + + respone = llm(prompt.format(category=category,input_text=input_text,no_words=no_words)) + print(respone) + return respone + + + +st.set_page_config(page_title = "Content-Creater", + layout='centered', + initial_sidebar_state = "collapsed") + + + +input_text = st.text_input("Write your creative words") + +col1,col2 = st.columns([5,5]) + +with col1: + no_words = st.text_input('Number of words') +with col2: + category = st.selectbox("category", + ('Essays', 'Poem', 'Joke', 'Blog'), + index=0) + +submit = st.button("Start") + +if submit: + st.write(getLlamaResponse(input_text, no_words, category)) \ No newline at end of file