Spaces:
Configuration error
Configuration error
File size: 1,918 Bytes
5f8765f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
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()
|