Spaces:
Configuration error
Configuration error
import streamlit as st | |
import google.generativeai as genai | |
from transformers import AutoTokenizer, AutoModelForCausalLM | |
import os | |
import json | |
# Configure page | |
st.set_page_config( | |
page_title="HerCorners", | |
page_icon="π", | |
layout="wide", | |
initial_sidebar_state="expanded" | |
) | |
# Initialize API keys safely | |
def initialize_apis(): | |
try: | |
# For Gemini | |
genai.configure(api_key=st.secrets["GEMINI_API_KEY"]) | |
# For Hugging Face | |
os.environ["HUGGINGFACE_API_TOKEN"] = st.secrets["HUGGINGFACE_API_KEY"] | |
return True | |
except Exception as e: | |
st.error(f"Error initializing APIs: {str(e)}") | |
return False | |
# Create configuration file for API settings | |
def create_config(): | |
config = { | |
"gemini_model": "gemini-pro", | |
"huggingface_model": "google/gemma-7b", | |
"max_tokens": 1000, | |
"temperature": 0.7 | |
} | |
return config | |
# Main application class | |
class HerCorners: | |
def __init__(self): | |
self.config = create_config() | |
self.apis_initialized = initialize_apis() | |
def generate_gemini_response(self, prompt): | |
try: | |
model = genai.GenerativeModel(self.config["gemini_model"]) | |
response = model.generate_content(prompt) | |
return response.text | |
except Exception as e: | |
st.error(f"Error generating response: {str(e)}") | |
return None | |
# Add other methods here... | |
# Main execution | |
def main(): | |
app = HerCorners() | |
if not app.apis_initialized: | |
st.warning("Please configure your API keys in the Space settings.") | |
st.info(""" | |
To add your API keys: | |
1. Go to your Space Settings | |
2. Navigate to 'Secrets' | |
3. Add GEMINI_API_KEY and HUGGINGFACE_API_KEY | |
""") | |
return | |
# Rest of your application code... | |
if __name__ == "__main__": | |
main() | |