Spaces:
Sleeping
Sleeping
Commit
Β·
9d3e192
unverified
Β·
0
Parent(s):
Initial commit with Git LFS for images
Browse files- .gitattributes +36 -0
- README.md +72 -0
- app.py +270 -0
- openai_client.py +48 -0
- requirements.txt +2 -0
- restart_app.sh +11 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Shakespeare AI
|
| 3 |
+
emoji: π»
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.44.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: cc-by-nc-sa-4.0
|
| 11 |
+
short_description: Rewrites .. stuff .. in Shakespearean English
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+

|
| 15 |
+
|
| 16 |
+
A Streamlit application that transforms modern text into Shakespearean English using various system prompts.
|
| 17 |
+
|
| 18 |
+
## Features
|
| 19 |
+
|
| 20 |
+
- Transform any text into Shakespearean English
|
| 21 |
+
- Multiple transformation styles for different types of content
|
| 22 |
+
- Easy-to-use interface with input and output areas
|
| 23 |
+
- Copy and clear functionality for convenience
|
| 24 |
+
- Secure API key input
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
## Usage
|
| 29 |
+
|
| 30 |
+
1. Run the Streamlit application:
|
| 31 |
+
```
|
| 32 |
+
streamlit run app.py
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
2. Open your web browser and navigate to the URL displayed in the terminal (usually http://localhost:8501)
|
| 36 |
+
|
| 37 |
+
3. Enter your OpenAI API key in the sidebar
|
| 38 |
+
|
| 39 |
+
4. Select a transformation style from the dropdown menu
|
| 40 |
+
|
| 41 |
+
5. Enter your text in the input area
|
| 42 |
+
|
| 43 |
+
6. Click the "Transform to Shakespearean" button
|
| 44 |
+
|
| 45 |
+
7. View the transformed text in the output area
|
| 46 |
+
|
| 47 |
+
8. Use the "Copy Text" button to copy the transformed text to your clipboard
|
| 48 |
+
|
| 49 |
+
9. Use the "Clear Text" button to clear the output
|
| 50 |
+
|
| 51 |
+
## System Prompts
|
| 52 |
+
|
| 53 |
+
The application uses a collection of system prompts organized in the `system-prompts` directory. These prompts are designed to transform different types of content into Shakespearean English, including:
|
| 54 |
+
|
| 55 |
+
- Basic transformations
|
| 56 |
+
- Business tools
|
| 57 |
+
- Various formats (emails, social media posts, etc.)
|
| 58 |
+
- Different purposes (documentation, copywriting, etc.)
|
| 59 |
+
|
| 60 |
+
Each prompt provides specific instructions for transforming text in a way that's appropriate for the content type.
|
| 61 |
+
|
| 62 |
+
## Requirements
|
| 63 |
+
|
| 64 |
+
- Python 3.7+
|
| 65 |
+
- Streamlit
|
| 66 |
+
- OpenAI API key
|
| 67 |
+
|
| 68 |
+
## Note
|
| 69 |
+
|
| 70 |
+
This application requires an OpenAI API key to function. You can obtain an API key by signing up at [OpenAI's website](https://platform.openai.com/signup).
|
| 71 |
+
|
| 72 |
+
|
app.py
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import random
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
# Import our clean OpenAI client implementation
|
| 7 |
+
from openai_client import generate_completion
|
| 8 |
+
|
| 9 |
+
# Set page configuration
|
| 10 |
+
st.set_page_config(
|
| 11 |
+
page_title="Shakespearean Text Generator",
|
| 12 |
+
page_icon="π",
|
| 13 |
+
layout="wide",
|
| 14 |
+
initial_sidebar_state="expanded"
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# Custom CSS for styling
|
| 18 |
+
def local_css():
|
| 19 |
+
st.markdown("""
|
| 20 |
+
<style>
|
| 21 |
+
.main {
|
| 22 |
+
background-color: #f5f5f0;
|
| 23 |
+
background-image: url("https://www.transparenttextures.com/patterns/old-paper.png");
|
| 24 |
+
}
|
| 25 |
+
.stApp {
|
| 26 |
+
font-family: 'Garamond', 'Georgia', serif;
|
| 27 |
+
}
|
| 28 |
+
h1, h2, h3 {
|
| 29 |
+
font-family: 'Garamond', 'Georgia', serif;
|
| 30 |
+
color: #5c3317;
|
| 31 |
+
}
|
| 32 |
+
.stButton>button {
|
| 33 |
+
background-color: #5c3317;
|
| 34 |
+
color: white;
|
| 35 |
+
border-radius: 5px;
|
| 36 |
+
font-family: 'Garamond', 'Georgia', serif;
|
| 37 |
+
font-weight: bold;
|
| 38 |
+
}
|
| 39 |
+
.stButton>button:hover {
|
| 40 |
+
background-color: #8b4513;
|
| 41 |
+
color: white;
|
| 42 |
+
}
|
| 43 |
+
.stTextArea>div>div>textarea {
|
| 44 |
+
border: 2px solid #8b4513;
|
| 45 |
+
border-radius: 5px;
|
| 46 |
+
font-family: 'Garamond', 'Georgia', serif;
|
| 47 |
+
}
|
| 48 |
+
.sidebar .sidebar-content {
|
| 49 |
+
background-color: #f5f5f0;
|
| 50 |
+
background-image: url("https://www.transparenttextures.com/patterns/old-paper.png");
|
| 51 |
+
}
|
| 52 |
+
.decoration {
|
| 53 |
+
text-align: center;
|
| 54 |
+
font-size: 24px;
|
| 55 |
+
color: #5c3317;
|
| 56 |
+
margin: 10px 0;
|
| 57 |
+
}
|
| 58 |
+
.shakespeare-quote {
|
| 59 |
+
font-style: italic;
|
| 60 |
+
text-align: center;
|
| 61 |
+
color: #5c3317;
|
| 62 |
+
padding: 10px;
|
| 63 |
+
border-left: 3px solid #8b4513;
|
| 64 |
+
margin: 10px 0;
|
| 65 |
+
}
|
| 66 |
+
.copy-btn {
|
| 67 |
+
position: absolute;
|
| 68 |
+
top: 10px;
|
| 69 |
+
right: 10px;
|
| 70 |
+
z-index: 1000;
|
| 71 |
+
}
|
| 72 |
+
</style>
|
| 73 |
+
""", unsafe_allow_html=True)
|
| 74 |
+
|
| 75 |
+
# Function to scan and get all system prompts
|
| 76 |
+
def get_system_prompts():
|
| 77 |
+
prompts = {}
|
| 78 |
+
base_dir = Path("system-prompts")
|
| 79 |
+
|
| 80 |
+
# Check if the directory exists
|
| 81 |
+
if not base_dir.exists():
|
| 82 |
+
st.error(f"System prompts directory not found: {base_dir}")
|
| 83 |
+
return {"Default": "system-prompts/basic-transformation/foundational.md"}
|
| 84 |
+
|
| 85 |
+
# Find all markdown files
|
| 86 |
+
md_files = list(base_dir.glob("**/*.md"))
|
| 87 |
+
|
| 88 |
+
# If no files found, return a default
|
| 89 |
+
if not md_files:
|
| 90 |
+
st.warning("No system prompt files found. Using default.")
|
| 91 |
+
return {"Default": "system-prompts/basic-transformation/foundational.md"}
|
| 92 |
+
|
| 93 |
+
for prompt_file in md_files:
|
| 94 |
+
# Create a friendly name from the path
|
| 95 |
+
relative_path = prompt_file.relative_to(base_dir)
|
| 96 |
+
friendly_name = str(relative_path).replace(".md", "").replace("/", " > ")
|
| 97 |
+
|
| 98 |
+
# Store the path and friendly name
|
| 99 |
+
prompts[friendly_name] = str(prompt_file)
|
| 100 |
+
|
| 101 |
+
return prompts
|
| 102 |
+
|
| 103 |
+
# Function to read the content of a system prompt
|
| 104 |
+
def read_system_prompt(prompt_path):
|
| 105 |
+
try:
|
| 106 |
+
with open(prompt_path, "r") as f:
|
| 107 |
+
return f.read()
|
| 108 |
+
except FileNotFoundError:
|
| 109 |
+
st.error(f"System prompt file not found: {prompt_path}")
|
| 110 |
+
return "You are Shakespeare, the greatest playwright and poet. Transform the user's text into Shakespearean English, maintaining the original meaning but using the vocabulary, grammar, and style of Shakespeare's works."
|
| 111 |
+
except Exception as e:
|
| 112 |
+
st.error(f"Error reading system prompt: {str(e)}")
|
| 113 |
+
return "You are Shakespeare, the greatest playwright and poet. Transform the user's text into Shakespearean English, maintaining the original meaning but using the vocabulary, grammar, and style of Shakespeare's works."
|
| 114 |
+
|
| 115 |
+
# Function to transform text using OpenAI API
|
| 116 |
+
def transform_text(api_key, system_prompt, user_text, model="gpt-4"):
|
| 117 |
+
"""
|
| 118 |
+
Wrapper function that uses our clean OpenAI client implementation
|
| 119 |
+
"""
|
| 120 |
+
return generate_completion(api_key, system_prompt, user_text, model)
|
| 121 |
+
|
| 122 |
+
# Main app
|
| 123 |
+
def main():
|
| 124 |
+
# Apply custom CSS
|
| 125 |
+
local_css()
|
| 126 |
+
|
| 127 |
+
# Display banner image with animation
|
| 128 |
+
st.image("shakespearegpt.png", use_column_width=True)
|
| 129 |
+
|
| 130 |
+
# App title and description
|
| 131 |
+
st.title("Shakespearean Text Generator")
|
| 132 |
+
st.markdown("""
|
| 133 |
+
<div class="decoration">βοΈ βοΈ βοΈ</div>
|
| 134 |
+
<p style="font-size: 18px; text-align: center;">
|
| 135 |
+
Transform thy modern text into eloquent Shakespearean prose!<br>
|
| 136 |
+
Select a transformation style, enter thy text, and watch as 'tis transformed into the language of the Bard.
|
| 137 |
+
</p>
|
| 138 |
+
<div class="decoration">βοΈ βοΈ βοΈ</div>
|
| 139 |
+
""", unsafe_allow_html=True)
|
| 140 |
+
|
| 141 |
+
# Random Shakespeare quote
|
| 142 |
+
quotes = [
|
| 143 |
+
"All the world's a stage, and all the men and women merely players.",
|
| 144 |
+
"The course of true love never did run smooth.",
|
| 145 |
+
"To be, or not to be, that is the question.",
|
| 146 |
+
"What's in a name? That which we call a rose by any other name would smell as sweet.",
|
| 147 |
+
"Some are born great, some achieve greatness, and some have greatness thrust upon them.",
|
| 148 |
+
"Love all, trust a few, do wrong to none.",
|
| 149 |
+
"We know what we are, but know not what we may be.",
|
| 150 |
+
"The fool doth think he is wise, but the wise man knows himself to be a fool.",
|
| 151 |
+
"All that glitters is not gold.",
|
| 152 |
+
"Be not afraid of greatness. Some are born great, some achieve greatness, and others have greatness thrust upon them."
|
| 153 |
+
]
|
| 154 |
+
|
| 155 |
+
st.markdown(f"""
|
| 156 |
+
<div class="shakespeare-quote">
|
| 157 |
+
"{random.choice(quotes)}"<br>
|
| 158 |
+
<small>- William Shakespeare</small>
|
| 159 |
+
</div>
|
| 160 |
+
""", unsafe_allow_html=True)
|
| 161 |
+
|
| 162 |
+
# Sidebar for API key and settings
|
| 163 |
+
with st.sidebar:
|
| 164 |
+
st.header("π OPENAI API KEY")
|
| 165 |
+
api_key = st.text_input("ENTER THY OPENAI API KEY", type="password")
|
| 166 |
+
st.markdown("Thy API key is required to use the OpenAI GPT models for text transformation.")
|
| 167 |
+
|
| 168 |
+
# Model selection
|
| 169 |
+
st.header("βοΈ SETTINGS")
|
| 170 |
+
model = st.selectbox(
|
| 171 |
+
"SELECT THY GPT MODEL",
|
| 172 |
+
["gpt-4", "gpt-3.5-turbo"],
|
| 173 |
+
index=0
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
st.divider()
|
| 177 |
+
|
| 178 |
+
# About section
|
| 179 |
+
st.header("π About")
|
| 180 |
+
st.markdown("""
|
| 181 |
+
This application uses OpenAI's GPT models to transform text into Shakespearean English.
|
| 182 |
+
|
| 183 |
+
The system prompts used for transformation are from a curated collection designed to mimic
|
| 184 |
+
various Shakespearean styles for different types of content.
|
| 185 |
+
|
| 186 |
+
<div class="decoration">βοΈ βοΈ βοΈ</div>
|
| 187 |
+
|
| 188 |
+
"O for a Muse of fire, that would ascend<br>
|
| 189 |
+
The brightest heaven of invention!"<br>
|
| 190 |
+
<small>- Henry V</small>
|
| 191 |
+
""", unsafe_allow_html=True)
|
| 192 |
+
|
| 193 |
+
# Main content area with two columns
|
| 194 |
+
col1, col2 = st.columns(2)
|
| 195 |
+
|
| 196 |
+
with col1:
|
| 197 |
+
st.header("π INPUT")
|
| 198 |
+
|
| 199 |
+
# Get all system prompts
|
| 200 |
+
prompts = get_system_prompts()
|
| 201 |
+
prompt_names = list(prompts.keys())
|
| 202 |
+
|
| 203 |
+
# Dropdown to select transformation
|
| 204 |
+
selected_prompt_name = st.selectbox("SELECT TRANSFORMATION STYLE", prompt_names)
|
| 205 |
+
selected_prompt_path = prompts[selected_prompt_name]
|
| 206 |
+
|
| 207 |
+
# Display the selected prompt description
|
| 208 |
+
with st.expander("VIEW TRANSFORMATION DESCRIPTION"):
|
| 209 |
+
st.markdown(read_system_prompt(selected_prompt_path))
|
| 210 |
+
|
| 211 |
+
# Text input area
|
| 212 |
+
user_text = st.text_area("ENTER THY TEXT", height=300,
|
| 213 |
+
placeholder="Type or paste thy modern text here...")
|
| 214 |
+
|
| 215 |
+
# Transform button with animation
|
| 216 |
+
transform_col1, transform_col2, transform_col3 = st.columns([1, 2, 1])
|
| 217 |
+
with transform_col2:
|
| 218 |
+
if st.button("β¨ TRANSFORM TO SHAKESPEAREAN β¨", use_container_width=True):
|
| 219 |
+
if not api_key:
|
| 220 |
+
st.error("Prithee, enter thy OpenAI API key in the sidebar.")
|
| 221 |
+
elif not user_text:
|
| 222 |
+
st.error("Thou must enter some text to transform.")
|
| 223 |
+
else:
|
| 224 |
+
with st.spinner("Transforming... The Bard is at work!"):
|
| 225 |
+
system_prompt = read_system_prompt(selected_prompt_path)
|
| 226 |
+
st.session_state.transformed_text = transform_text(api_key, system_prompt, user_text, model)
|
| 227 |
+
|
| 228 |
+
with col2:
|
| 229 |
+
st.header("π SHAKESPEAREAN OUTPUT")
|
| 230 |
+
|
| 231 |
+
# Initialize session state for transformed text if it doesn't exist
|
| 232 |
+
if "transformed_text" not in st.session_state:
|
| 233 |
+
st.session_state.transformed_text = ""
|
| 234 |
+
|
| 235 |
+
# Display transformed text with styling
|
| 236 |
+
st.markdown('<div style="position: relative;">', unsafe_allow_html=True)
|
| 237 |
+
transformed_text = st.text_area(
|
| 238 |
+
"TRANSFORMED TEXT",
|
| 239 |
+
value=st.session_state.transformed_text,
|
| 240 |
+
height=300,
|
| 241 |
+
placeholder="The Bard's words shall appear here..."
|
| 242 |
+
)
|
| 243 |
+
|
| 244 |
+
# Buttons for copy and clear
|
| 245 |
+
col_copy, col_space, col_clear = st.columns([1, 1, 1])
|
| 246 |
+
|
| 247 |
+
with col_copy:
|
| 248 |
+
if st.button("π COPY TEXT", use_container_width=True):
|
| 249 |
+
# Use Streamlit's built-in functionality for clipboard
|
| 250 |
+
st.code(transformed_text, language="text")
|
| 251 |
+
st.success("Text copied to clipboard! You can also use the copy button in the code block above.")
|
| 252 |
+
|
| 253 |
+
with col_clear:
|
| 254 |
+
if st.button("π§Ή CLEAR TEXT", use_container_width=True):
|
| 255 |
+
st.session_state.transformed_text = ""
|
| 256 |
+
st.rerun()
|
| 257 |
+
|
| 258 |
+
# Add a fun element - Shakespeare emoji reactions
|
| 259 |
+
if st.session_state.transformed_text:
|
| 260 |
+
st.markdown('<div class="decoration" style="margin-top: 20px;">', unsafe_allow_html=True)
|
| 261 |
+
reactions = ["π", "π", "π", "ποΈ", "π", "βοΈ", "π°", "π§ββοΈ"]
|
| 262 |
+
st.markdown(f"""
|
| 263 |
+
<div style="text-align: center; margin-top: 20px;">
|
| 264 |
+
<p>Shakespeare would be {random.choice(['proud', 'delighted', 'amused', 'impressed'])}!</p>
|
| 265 |
+
<p style="font-size: 24px;">{' '.join(random.sample(reactions, 4))}</p>
|
| 266 |
+
</div>
|
| 267 |
+
""", unsafe_allow_html=True)
|
| 268 |
+
|
| 269 |
+
if __name__ == "__main__":
|
| 270 |
+
main()
|
openai_client.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A direct implementation using requests to bypass the OpenAI SDK entirely.
|
| 3 |
+
This avoids any issues with the OpenAI client configuration.
|
| 4 |
+
"""
|
| 5 |
+
import requests
|
| 6 |
+
import json
|
| 7 |
+
|
| 8 |
+
def generate_completion(api_key, system_prompt, user_text, model="gpt-4"):
|
| 9 |
+
"""
|
| 10 |
+
Generate a completion by directly calling the OpenAI API using requests.
|
| 11 |
+
This bypasses the OpenAI SDK entirely.
|
| 12 |
+
"""
|
| 13 |
+
if not api_key or not system_prompt or not user_text:
|
| 14 |
+
return "Please provide an API key, select a transformation, and enter some text."
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
# OpenAI API endpoint
|
| 18 |
+
url = "https://api.openai.com/v1/chat/completions"
|
| 19 |
+
|
| 20 |
+
# Headers with API key
|
| 21 |
+
headers = {
|
| 22 |
+
"Content-Type": "application/json",
|
| 23 |
+
"Authorization": f"Bearer {api_key}"
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
# Request payload
|
| 27 |
+
payload = {
|
| 28 |
+
"model": model,
|
| 29 |
+
"messages": [
|
| 30 |
+
{"role": "system", "content": system_prompt},
|
| 31 |
+
{"role": "user", "content": user_text}
|
| 32 |
+
],
|
| 33 |
+
"temperature": 0.7,
|
| 34 |
+
"max_tokens": 2000
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
# Make the API call directly using requests
|
| 38 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 39 |
+
|
| 40 |
+
# Check if the request was successful
|
| 41 |
+
if response.status_code == 200:
|
| 42 |
+
response_data = response.json()
|
| 43 |
+
return response_data["choices"][0]["message"]["content"]
|
| 44 |
+
else:
|
| 45 |
+
return f"Error: API returned status code {response.status_code}. {response.text}"
|
| 46 |
+
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f"Error: {str(e)}"
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.32.0
|
| 2 |
+
openai==1.12.0
|
restart_app.sh
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Kill any running Streamlit processes
|
| 4 |
+
pkill -f streamlit
|
| 5 |
+
|
| 6 |
+
# Wait a moment for processes to terminate
|
| 7 |
+
sleep 1
|
| 8 |
+
|
| 9 |
+
# Activate virtual environment and run the app
|
| 10 |
+
source .venv/bin/activate
|
| 11 |
+
streamlit run app.py --server.fileWatcherType none
|