Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,75 +1,75 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from langchain_community.llms import Ollama
|
| 3 |
-
from langchain.chains import LLMChain
|
| 4 |
-
from langchain_core.prompts import ChatPromptTemplate
|
| 5 |
-
from langchain_core.output_parsers import StrOutputParser
|
| 6 |
-
from langchain_huggingface import HuggingFaceEndpoint
|
| 7 |
-
# from dotenv import load_dotenv
|
| 8 |
-
# load_dotenv()
|
| 9 |
-
|
| 10 |
-
# Initialize Ollama LLM
|
| 11 |
-
# llm = HuggingFaceEndpoint(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.7, "max_length": 512})
|
| 12 |
-
parser = StrOutputParser()
|
| 13 |
-
|
| 14 |
-
repo_id = "mistralai/Mistral-7B-Instruct-v0.2"
|
| 15 |
-
|
| 16 |
-
llm = HuggingFaceEndpoint(
|
| 17 |
-
repo_id=repo_id,
|
| 18 |
-
temperature=0.5
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
system_template = """You are an AI assistant specialized in writing personalized, professional emails.
|
| 23 |
-
Your task is to generate an email based on the provided information.
|
| 24 |
-
The email should be engaging, concise, and highlight the key benefits of the project. Use bullet pointers. Maximum words allowed are 250. Always start with Subject line."""
|
| 25 |
-
|
| 26 |
-
user_template = """Write a personalized email to {name} about the {project} project.
|
| 27 |
-
Highlight the following key benefits:
|
| 28 |
-
{key_benefits}
|
| 29 |
-
|
| 30 |
-
The email should be professional, engaging, and no longer than 3 paragraphs."""
|
| 31 |
-
|
| 32 |
-
prompt_template = ChatPromptTemplate.from_messages(
|
| 33 |
-
[("system", system_template), ("user", user_template)]
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
# Create an LLMChain
|
| 37 |
-
email_chain = prompt_template|llm
|
| 38 |
-
# |parser
|
| 39 |
-
|
| 40 |
-
# Streamlit UI
|
| 41 |
-
st.title("Personalized Email Generator")
|
| 42 |
-
|
| 43 |
-
name = st.text_input("Recipient's Name")
|
| 44 |
-
project = st.text_input("Project Name")
|
| 45 |
-
key_benefits = st.text_area("Key Benefits (one per line)")
|
| 46 |
-
|
| 47 |
-
if st.button("Generate Email"):
|
| 48 |
-
if name and project and key_benefits:
|
| 49 |
-
benefits_list = key_benefits.split('\n')
|
| 50 |
-
benefits_str = ", ".join(benefits_list)
|
| 51 |
-
|
| 52 |
-
email = email_chain.invoke({"name": name, "project": project, "key_benefits": key_benefits})
|
| 53 |
-
st.subheader("Generated Email:")
|
| 54 |
-
st.text_area("", email, height=300)
|
| 55 |
-
else:
|
| 56 |
-
st.error("Please fill in all fields.")
|
| 57 |
-
|
| 58 |
-
# Instructions
|
| 59 |
-
st.sidebar.header("Instructions")
|
| 60 |
-
st.sidebar.info(
|
| 61 |
-
"1. Enter the recipient's name.\n"
|
| 62 |
-
"2. Specify the project name.\n"
|
| 63 |
-
"3. List key benefits, one per line.\n"
|
| 64 |
-
"4. Click 'Generate Email' to create a personalized email."
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
# About
|
| 68 |
-
st.sidebar.header("About")
|
| 69 |
-
st.sidebar.info(
|
| 70 |
-
"This app uses Langchain with
|
| 71 |
-
"based on the provided information. It demonstrates how Large Language Models "
|
| 72 |
-
"can be used for dynamic content creation."
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_community.llms import Ollama
|
| 3 |
+
from langchain.chains import LLMChain
|
| 4 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 5 |
+
from langchain_core.output_parsers import StrOutputParser
|
| 6 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
| 7 |
+
# from dotenv import load_dotenv
|
| 8 |
+
# load_dotenv()
|
| 9 |
+
|
| 10 |
+
# Initialize Ollama LLM
|
| 11 |
+
# llm = HuggingFaceEndpoint(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.7, "max_length": 512})
|
| 12 |
+
parser = StrOutputParser()
|
| 13 |
+
|
| 14 |
+
repo_id = "mistralai/Mistral-7B-Instruct-v0.2"
|
| 15 |
+
|
| 16 |
+
llm = HuggingFaceEndpoint(
|
| 17 |
+
repo_id=repo_id,
|
| 18 |
+
temperature=0.5
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
system_template = """You are an AI assistant specialized in writing personalized, professional emails.
|
| 23 |
+
Your task is to generate an email based on the provided information.
|
| 24 |
+
The email should be engaging, concise, and highlight the key benefits of the project. Use bullet pointers. Maximum words allowed are 250. Always start with Subject line."""
|
| 25 |
+
|
| 26 |
+
user_template = """Write a personalized email to {name} about the {project} project.
|
| 27 |
+
Highlight the following key benefits:
|
| 28 |
+
{key_benefits}
|
| 29 |
+
|
| 30 |
+
The email should be professional, engaging, and no longer than 3 paragraphs."""
|
| 31 |
+
|
| 32 |
+
prompt_template = ChatPromptTemplate.from_messages(
|
| 33 |
+
[("system", system_template), ("user", user_template)]
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Create an LLMChain
|
| 37 |
+
email_chain = prompt_template|llm
|
| 38 |
+
# |parser
|
| 39 |
+
|
| 40 |
+
# Streamlit UI
|
| 41 |
+
st.title("Personalized Email Generator")
|
| 42 |
+
|
| 43 |
+
name = st.text_input("Recipient's Name")
|
| 44 |
+
project = st.text_input("Project Name")
|
| 45 |
+
key_benefits = st.text_area("Key Benefits (one per line)")
|
| 46 |
+
|
| 47 |
+
if st.button("Generate Email"):
|
| 48 |
+
if name and project and key_benefits:
|
| 49 |
+
benefits_list = key_benefits.split('\n')
|
| 50 |
+
benefits_str = ", ".join(benefits_list)
|
| 51 |
+
|
| 52 |
+
email = email_chain.invoke({"name": name, "project": project, "key_benefits": key_benefits})
|
| 53 |
+
st.subheader("Generated Email:")
|
| 54 |
+
st.text_area("", email, height=300)
|
| 55 |
+
else:
|
| 56 |
+
st.error("Please fill in all fields.")
|
| 57 |
+
|
| 58 |
+
# Instructions
|
| 59 |
+
st.sidebar.header("Instructions")
|
| 60 |
+
st.sidebar.info(
|
| 61 |
+
"1. Enter the recipient's name.\n"
|
| 62 |
+
"2. Specify the project name.\n"
|
| 63 |
+
"3. List key benefits, one per line.\n"
|
| 64 |
+
"4. Click 'Generate Email' to create a personalized email."
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# About
|
| 68 |
+
st.sidebar.header("About")
|
| 69 |
+
st.sidebar.info(
|
| 70 |
+
"This app uses Langchain with Huggingface to generate personalized emails "
|
| 71 |
+
"based on the provided information. It demonstrates how Large Language Models "
|
| 72 |
+
"can be used for dynamic content creation."
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
|