Spaces:
Sleeping
Sleeping
Download app.py from xiakshay/Email_write: direct link, hf CLI and curl.
- Browser
- Download file 3.4 kB
-
https://huggingface.co/spaces/xiakshay/Email_write/resolve/main/app.py
- Command line
-
hf download hf://spaces/xiakshay/Email_write/app.py
-
curl -L -o app.py https://huggingface.co/spaces/xiakshay/Email_write/resolve/main/app.py
3.4 kB
| from dotenv import load_dotenv | |
| import streamlit as st | |
| import os | |
| from PIL import Image | |
| import google.generativeai as genai | |
| st.set_page_config(page_title="Professional content writer", layout="wide") # Optional: Set wide layout | |
| # background_style = f""" | |
| # body {{ | |
| # background-image: url("image.jpeg"); /* Replace with your image path */ | |
| # background-size: cover; | |
| # background-repeat: no-repeat; | |
| # background-position: center; | |
| # margin: 0; | |
| # padding: 0; | |
| # }} | |
| # """ | |
| # st.write('<style>{}</style>'.format(background_style), unsafe_allow_html=True) | |
| # ... rest of your code ... | |
| # Load environment variables | |
| load_dotenv() | |
| # Configure API key | |
| genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) | |
| # Function to load content based on selected type | |
| def generate_content(content_type, input_name, input_receiver, input_subject, input_prompt, previous_context=None): | |
| input_title = None | |
| if content_type == 'Email': | |
| input_title = f"{input_name} wants to write an email to {input_receiver} about {input_subject} which says about {input_prompt}" | |
| elif content_type == 'LinkedIn Message': | |
| if previous_context: | |
| input_subject += f" The last messages I got was about {previous_context}" | |
| input_title = f"{input_name} wants to send a LinkedIn message to {input_receiver} about {input_subject} which says about {input_prompt} make sure to show my skills and focus on what I want to say. Use professional words and show some respect. also tell that check my resume and give suggestions if needed to match the job profile." | |
| elif content_type == 'Connection Request': | |
| input_title = f"start with hi {input_receiver} and focus on {input_subject} which says about {input_prompt}, this should be not more than 25 words. write in formal and professional way. I want to connect with that guy so make it happen in limited words. don't use anything like- they are good or not or warm regards. in short message we don't use thimething like this." | |
| model = genai.GenerativeModel('gemini-pro') | |
| try: | |
| response = model.generate_content([input_prompt, input_title]) | |
| return response.text | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Streamlit interface | |
| # st.set_page_config(page_title="Professional Content Writer") | |
| st.header("Gemini Application") | |
| # User inputs | |
| input_name = st.text_input("Input Your name: ", key="input1") | |
| input_receiver = st.text_input("Input receiver name: ", key="input2") | |
| input_subject = st.text_input("Input subject: ", key="input3") | |
| input_prompt = st.text_input("Input some prompts: ", key="input4") | |
| # Select content type | |
| content_types = ['Email', 'LinkedIn Message', 'Connection Request'] | |
| selected_content_type = st.selectbox("Select Content Type:", content_types) | |
| previous_context = None | |
| if selected_content_type == 'LinkedIn Message': | |
| previous_context = st.text_input("Input the previous context:", key="input5") | |
| # Generate button | |
| submit = st.button("Generate") | |
| if submit: | |
| if input_name.strip() == "" or input_receiver.strip() == "" or input_subject.strip() == "" or input_prompt.strip() == "": | |
| st.error("Please fill in all fields.") | |
| else: | |
| response = generate_content(selected_content_type, input_name, input_receiver, input_subject, input_prompt, previous_context) | |
| st.subheader(selected_content_type) | |
| st.write(response) | |