Spaces:
Sleeping
Sleeping
File size: 3,113 Bytes
f187973 1bdcde8 f187973 1bdcde8 75c97f7 1bdcde8 f187973 072edf1 1bdcde8 f187973 1bdcde8 f187973 1bdcde8 f187973 1bdcde8 f187973 1bdcde8 f187973 1bdcde8 f187973 1bdcde8 f187973 1bdcde8 8ee5ed6 1bdcde8 8ee5ed6 1bdcde8 f187973 1bdcde8 f187973 1bdcde8 f187973 1bdcde8 |
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 84 85 86 87 |
import streamlit as st
import random
import openai
from PIL import Image
import requests
# Set your OpenAI API key
openai.api_key = "OPENAI_API_KEY" # Replace with your OpenAI API key
# Load predefined quotes dataset (Here, using a static example for now)
random_text = "The only way to do great work is to love what you do."
random_author = "Steve Jobs"
# Load user-submitted quotes
if "user_quotes" not in st.session_state:
st.session_state.user_quotes = []
# Set up Streamlit page
st.set_page_config(page_title="Quotation of the Day", page_icon="π", layout="centered")
st.title("π Quotation of the Day")
# Show a predefined quote
st.write(f"π£οΈ *{random_text}* β {random_author}")
# AI-Generated Quote Image
st.subheader("πΌοΈ AI-Generated Quote Image")
if st.button("Generate Quote Image"):
# Call OpenAI's DALLΒ·E model to generate an image from the quote
response = openai.Image.create(
prompt=random_text, # Use the random quote as the prompt
n=1, # Generate 1 image
size="1024x1024" # Image size
)
# Extract the image URL from the response
image_url = response['data'][0]['url']
# Display the image
st.image(image_url, caption="AI-Generated Quote Image")
# AI-Generated Quote (Using GPT-3)
st.subheader("π‘ Get an AI-Generated Quote")
if st.button("Generate AI Quote"):
# Call OpenAI's GPT-3 model to generate a quote
response = openai.Completion.create(
engine="text-davinci-003", # Choose the GPT-3 model
prompt="A great quote is", # Starting text for the quote
max_tokens=50 # Limit the number of tokens (words/characters)
)
# Get the generated quote
ai_quote = response.choices[0].text.strip()
# Display the AI-generated quote
st.write(f"β¨ *{ai_quote}* β AI")
# User Authentication with Hugging Face (In this case, weβre not using it)
st.subheader("π Submit Your Own Quote")
if "username" not in st.session_state:
username = st.text_input("Enter your name (for quote submission)")
if st.button("Submit"):
st.session_state.username = username
st.success(f"β
Logged in as {username}")
# Submit Your Own Quote
if "username" in st.session_state:
st.subheader("π Submit Your Own Quote")
user_quote = st.text_area("Enter your quote")
if st.button("Submit Quote"):
if user_quote.strip():
st.session_state.user_quotes.append({'quote': user_quote, 'author': st.session_state.username})
st.success("β
Quote added successfully!")
else:
st.error("β Please enter a quote!")
# Display community quotes (user-submitted quotes)
st.subheader("π Community Quotes")
for i, q in enumerate(st.session_state.user_quotes):
col1, col2 = st.columns([4, 1])
with col1:
st.write(f"π¬ *{q['quote']}* β {q['author']}")
with col2:
if st.button(f"Upvote {i}", key=f"upvote_{i}"):
st.session_state.user_quotes[i]['upvotes'] = st.session_state.user_quotes.get('upvotes', 0) + 1
st.experimental_rerun()
|