Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import os | |
| import json | |
| import google.generativeai as genai | |
| API_KEY = "AIzaSyCA4__JMC_ZIQ9xQegIj5LOMLhSSrn3pMw" | |
| def configure_genai_api(): | |
| genai.configure(api_key=API_KEY) | |
| generation_config = { | |
| "temperature": 0.9, | |
| "top_p": 1, | |
| "top_k": 40, | |
| "max_output_tokens": 2048, | |
| } | |
| safety_settings = [ | |
| {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| ] | |
| return genai.GenerativeModel(model_name="gemini-1.0-pro", | |
| generation_config=generation_config, | |
| safety_settings=safety_settings) | |
| def load_user_data(): | |
| try: | |
| with open('gemini_responses.json', 'r') as file: | |
| return json.load(file) | |
| except FileNotFoundError: | |
| st.error("User data file not found. Please ensure 'gemini_responses.json' exists.") | |
| return {} | |
| def load_data(): | |
| try: | |
| with open('data.json', 'r') as file: | |
| return json.load(file) | |
| except FileNotFoundError: | |
| st.error("Data file not found. Please ensure 'data.json' exists.") | |
| return {} | |
| def combine_responses(user_data, data, *args): | |
| combined_responses = [] | |
| for key, value in user_data.items(): | |
| combined_responses.append(f"{key}: {value}") | |
| combined_responses.append(f"Name: {data['name']}") | |
| combined_responses.append(f"Email: {data['email']}") | |
| for response_set in args: | |
| if isinstance(response_set, dict): | |
| combined_responses.extend(response_set.values()) | |
| elif isinstance(response_set, list): | |
| combined_responses.extend(response_set) | |
| combined_responses.extend(data.values()) # Add data.json values | |
| return " ".join(combined_responses) | |
| def app(): | |
| st.header("LinkedIn Profile Creator") | |
| model = configure_genai_api() | |
| if not model: | |
| return | |
| # Load user data | |
| user_data = load_user_data() | |
| data = load_data() # Add this line to load the missing 'data' argument | |
| combined_responses_text = combine_responses(user_data, data) # Pass the 'data' argument | |
| prompt_template = f""" | |
| Based on the following inputs, generate a professional bio and a short header bio that could be used on LinkedIn. | |
| {combined_responses_text} | |
| Provide optimized content for a LinkedIn Bio, Header Bio, Experience, Skills, Certifications. (dont give education section) | |
| """ | |
| try: | |
| response = model.generate_content([prompt_template]) | |
| st.subheader("Optimized LinkedIn Content") | |
| st.write("Based on your input, here's optimized content for your LinkedIn profile:") | |
| st.write(response.text) | |
| except Exception as e: | |
| st.error("An error occurred while generating your LinkedIn content. Please try again later.") | |
| st.error(f"Error: {e}") | |
| if __name__ == "__main__": | |
| app() | |