Spaces:
Runtime error
Runtime error
change api code from openai to gemini
Browse files
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
# Page Title
|
| 8 |
st.title("LemmaTeks: AI-Powered Text Generator")
|
|
@@ -46,25 +47,32 @@ if st.button("Generate"):
|
|
| 46 |
st.write("Generating responses...")
|
| 47 |
|
| 48 |
try:
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Display Responses
|
| 59 |
-
for i, choice in enumerate(
|
| 60 |
st.subheader(f"Response {i + 1}")
|
| 61 |
-
st.write(choice
|
| 62 |
-
|
| 63 |
-
except
|
| 64 |
-
st.error(f"
|
| 65 |
-
except openai.error.RateLimitError as e:
|
| 66 |
-
st.error(f"Rate limit exceeded. Please try again later: {e}")
|
| 67 |
-
except openai.OpenAIError as e: # This is the correct way for general OpenAI errors
|
| 68 |
-
st.error(f"OpenAI API error: {e}")
|
| 69 |
except Exception as e:
|
| 70 |
st.error(f"An unexpected error occurred: {e}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
+
# Gemini API key (replace with your actual API key or credentials)
|
| 6 |
+
gemini_api_key = st.secrets["gemini"]["api_key"]
|
| 7 |
|
| 8 |
# Page Title
|
| 9 |
st.title("LemmaTeks: AI-Powered Text Generator")
|
|
|
|
| 47 |
st.write("Generating responses...")
|
| 48 |
|
| 49 |
try:
|
| 50 |
+
# Set up the Gemini API endpoint (this is an example and should be adjusted)
|
| 51 |
+
api_url = "https://gemini.google.com/app" # Replace with actual URL
|
| 52 |
+
headers = {
|
| 53 |
+
"Authorization": f"Bearer {gemini_api_key}",
|
| 54 |
+
"Content-Type": "application/json"
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
# Set up the payload for the API request
|
| 58 |
+
payload = {
|
| 59 |
+
"model": "gemini", # Replace with the correct Gemini model name
|
| 60 |
+
"prompt": f"Format: {output_format}\nTone: {tone_style}\nPrompt: {user_prompt}",
|
| 61 |
+
"max_tokens": text_length,
|
| 62 |
+
"temperature": creativity_level,
|
| 63 |
+
"num_responses": num_responses
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
# Make the API request
|
| 67 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
| 68 |
+
response_data = response.json()
|
| 69 |
+
|
| 70 |
# Display Responses
|
| 71 |
+
for i, choice in enumerate(response_data["choices"]):
|
| 72 |
st.subheader(f"Response {i + 1}")
|
| 73 |
+
st.write(choice["text"].strip())
|
| 74 |
+
|
| 75 |
+
except requests.exceptions.RequestException as e:
|
| 76 |
+
st.error(f"An error occurred during the request: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
except Exception as e:
|
| 78 |
st.error(f"An unexpected error occurred: {e}")
|