Spaces:
Sleeping
Sleeping
File size: 2,746 Bytes
706f617 0214b2e 02dbdf8 0214b2e 0c71d91 0214b2e 0c71d91 706f617 06ab451 706f617 02dbdf8 0214b2e 0c71d91 0214b2e 0c71d91 0214b2e 706f617 f99419a 706f617 0c71d91 706f617 0214b2e 0c71d91 0214b2e 706f617 0214b2e 706f617 0214b2e 02dbdf8 0214b2e 0c71d91 0214b2e 706f617 4845e1d 0214b2e 0c71d91 |
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 75 76 77 78 79 80 81 82 83 |
import os
from groq import Groq
from openai import OpenAI
from anthropic import Anthropic
from google import genai
from google.genai import types
import streamlit as st
from dotenv import load_dotenv
load_dotenv()
st.set_page_config(page_title="strftime AI", page_icon="π")
with open("static/style.css", encoding="utf-8") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
st.header("strftime AI")
with st.sidebar:
provider = st.radio(
"Choose AI Provider",
options=[
"Groq",
"Gemini",
"OpenAI",
"Anthropic",
]
)
text = st.text_input("Enter datetime text eg. 2023-09-28T15:27:58Z", value="2023-09-28T15:27:58Z")
if text:
prompt = f"""Analyze this datetime string and convert it to strftime format: {text}
Please provide your response in exactly this format:
**strftime format:** `[the strftime format string]`
**Breakdown:**
- `%Y`: 4-digit year
- `%m`: 2-digit month (01-12)
- `%d`: 2-digit day (01-31)
[list each format code used with its meaning]
Be precise and only include the format codes that are actually present in the input datetime string. Do not add extra explanations or variations."""
if provider == "Groq":
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": prompt}],
model="gemma2-9b-it",
max_tokens=1024,
)
st.markdown(chat_completion.choices[0].message.content)
elif provider == "OpenAI":
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": prompt}],
model="gpt-4o-mini",
max_tokens=1024,
)
st.markdown(chat_completion.choices[0].message.content)
elif provider == "Anthropic":
client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
message = client.messages.create(
messages=[{"role": "user", "content": prompt}],
model="claude-3-haiku-20240307",
max_tokens=1024,
)
st.markdown(message.content[0].text)
elif provider == "Gemini":
client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
response = client.models.generate_content(
model='gemini-2.5-flash-lite',
contents = types.Content(
role='user',
parts=[types.Part.from_text(text=prompt)]
),
)
st.markdown(response.candidates[0].content.parts[0].text)
|