Spaces:
Sleeping
Sleeping
Neelesh
commited on
Commit
β’
706f617
1
Parent(s):
5f539c8
Add strftime AI application code and dependencies
Browse files- app.py +50 -0
- requirements.txt +4 -0
- static/style.css +8 -0
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import openai
|
4 |
+
import google.generativeai as palm
|
5 |
+
from anthropic import AI_PROMPT, HUMAN_PROMPT, Anthropic
|
6 |
+
import streamlit as st
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
st.set_page_config(page_title="strftime AI", page_icon="π")
|
12 |
+
|
13 |
+
with open("static/style.css") as f:
|
14 |
+
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
15 |
+
|
16 |
+
st.header("strftime AI")
|
17 |
+
|
18 |
+
with st.sidebar:
|
19 |
+
provider = st.radio("Choose AI Provider", options=["Anthropic", "Google Palm", "OpenAI"])
|
20 |
+
|
21 |
+
text = st.text_input("Enter datetime text eg. 2023-09-28T15:27:58Z")
|
22 |
+
|
23 |
+
if text:
|
24 |
+
prompt = ("Convert the following datetime string into strftime format, "
|
25 |
+
"show the strftime string on top and then breakdown of % symbols: " + text)
|
26 |
+
|
27 |
+
if provider == "Anthropic":
|
28 |
+
anthropic = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
29 |
+
completion = anthropic.completions.create(
|
30 |
+
model="claude-2",
|
31 |
+
max_tokens_to_sample=300,
|
32 |
+
prompt=f"{HUMAN_PROMPT} {prompt}{AI_PROMPT}",
|
33 |
+
)
|
34 |
+
st.text(completion.completion)
|
35 |
+
elif provider == "Google Palm":
|
36 |
+
palm.configure(api_key=os.getenv("PALM_API_KEY"))
|
37 |
+
completion = palm.generate_text(
|
38 |
+
model="models/text-bison-001",
|
39 |
+
prompt=prompt,
|
40 |
+
temperature=0,
|
41 |
+
max_output_tokens=800,
|
42 |
+
)
|
43 |
+
st.text(completion.result)
|
44 |
+
elif provider == "OpenAI":
|
45 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
46 |
+
chat_completion = openai.ChatCompletion.create(
|
47 |
+
model="gpt-3.5-turbo",
|
48 |
+
messages=[{"role": "user", "content": prompt}],
|
49 |
+
)
|
50 |
+
st.text(chat_completion.choices[0].message.content)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
anthropic
|
3 |
+
google-generativeai
|
4 |
+
python-dotenv
|
static/style.css
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
div.block-container.css-z5fcl4.egzxvld4 {
|
2 |
+
padding-top: 0;
|
3 |
+
padding-bottom: 20px;
|
4 |
+
}
|
5 |
+
|
6 |
+
footer {
|
7 |
+
display: none;
|
8 |
+
}
|