Spaces:
Sleeping
Sleeping
Adding partial codes for the app
Browse files- .streamlit/secrets.toml +2 -0
- app.py +64 -0
- requirements.txt +2 -0
.streamlit/secrets.toml
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
[openai]
|
2 |
+
api_key = "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"
|
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import openai
|
3 |
+
|
4 |
+
# OpenAI API key
|
5 |
+
openai.api_key = st.secrets ["openai"] ["api_key"]
|
6 |
+
|
7 |
+
# Page Title
|
8 |
+
st.title("LemmaTeks: AI-Powered Text Generator")
|
9 |
+
|
10 |
+
# Sidebar for Settings
|
11 |
+
with st.sidebar:
|
12 |
+
st.header("Configuration")
|
13 |
+
|
14 |
+
# Dropdown for Output Format
|
15 |
+
output_format = st.selectbox(
|
16 |
+
"Choose Output Format:",
|
17 |
+
["Story", "Poem", "Article", "Code"]
|
18 |
+
)
|
19 |
+
|
20 |
+
# Dropdown for Tone/Style
|
21 |
+
tone_style = st.selectbox(
|
22 |
+
"Select Tone/Style:",
|
23 |
+
["Formal", "Informal", "Humorous", "Technical"]
|
24 |
+
)
|
25 |
+
|
26 |
+
# Sliders for Text Length and Creativity
|
27 |
+
text_length = st.slider("Text Length (words):", min_value=50, max_value=1000, step=50)
|
28 |
+
creativity_level = st.slider("Creativity Level:", min_value=0.0, max_value=1.0, step=0.1)
|
29 |
+
|
30 |
+
# Number of Responses
|
31 |
+
num_responses = st.number_input("Number of Responses:", min_value=1, max_value=5, step=1)
|
32 |
+
|
33 |
+
# Checkboxes for Features
|
34 |
+
creative_mode = st.checkbox("Enable Creative Mode")
|
35 |
+
fact_checking = st.checkbox("Enable Fact-Checking")
|
36 |
+
|
37 |
+
# Text Input Field
|
38 |
+
user_prompt = st.text_area("Enter Your Prompt Here:")
|
39 |
+
|
40 |
+
# Submit Button
|
41 |
+
if st.button("Generate"):
|
42 |
+
if user_prompt.strip() == "":
|
43 |
+
st.warning("Please enter a prompt before generating!")
|
44 |
+
else:
|
45 |
+
# Process AI Request
|
46 |
+
st.write("Generating responses...")
|
47 |
+
|
48 |
+
try:
|
49 |
+
# OpenAI API call
|
50 |
+
response = openai.Completion.create(
|
51 |
+
engine="text-davinci-003", # GPT-3.5 engine
|
52 |
+
prompt=f"Format: {output_format}\nTone: {tone_style}\nPrompt: {user_prompt}",
|
53 |
+
max_tokens=text_length, # Approximate word count
|
54 |
+
temperature=creativity_level, # Creativity level
|
55 |
+
n=num_responses # Number of responses
|
56 |
+
)
|
57 |
+
|
58 |
+
# Display Responses
|
59 |
+
for i, choice in enumerate(response.choices):
|
60 |
+
st.subheader(f"Response {i + 1}")
|
61 |
+
st.write(choice.text.strip())
|
62 |
+
|
63 |
+
except openai.error.OpenAIError as e:
|
64 |
+
st.error(f"An error occurred: {e}")
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
openai
|