Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,17 @@ from fpdf import FPDF
|
|
7 |
from gtts import gTTS
|
8 |
import gradio as gr
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
|
11 |
from langchain.memory import ConversationBufferMemory
|
12 |
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
|
@@ -81,8 +92,13 @@ def save_story_to_file(character, story_text, age_group="kids", tone="", theme="
|
|
81 |
"theme": theme,
|
82 |
"timestamp": datetime.now().isoformat()
|
83 |
}
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# ---------------- Kids Prompt (ChatPromptTemplate) ----------------
|
88 |
kids_prompt = ChatPromptTemplate.from_messages([
|
@@ -444,5 +460,19 @@ with gr.Blocks(title="π Children's Story Assistant") as app:
|
|
444 |
refresh_btn = gr.Button("π Load Stories")
|
445 |
refresh_btn.click(fn=refresh_dropdown, outputs=story_selector)
|
446 |
story_selector.change(fn=show_story_by_title, inputs=story_selector, outputs=story_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
|
448 |
app.launch()
|
|
|
7 |
from gtts import gTTS
|
8 |
import gradio as gr
|
9 |
|
10 |
+
firebase_config = {
|
11 |
+
"apiKey": os.getenv("FIREBASE_API_KEY"),
|
12 |
+
"authDomain": os.getenv("FIREBASE_AUTH_DOMAIN"),
|
13 |
+
"databaseURL": os.getenv("FIREBASE_DATABASE_URL"),
|
14 |
+
"projectId": os.getenv("FIREBASE_PROJECT_ID"),
|
15 |
+
"storageBucket": os.getenv("FIREBASE_STORAGE_BUCKET"),
|
16 |
+
"messagingSenderId": os.getenv("FIREBASE_MESSAGING_SENDER_ID"),
|
17 |
+
"appId": os.getenv("FIREBASE_APP_ID")
|
18 |
+
}
|
19 |
+
|
20 |
+
|
21 |
from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
|
22 |
from langchain.memory import ConversationBufferMemory
|
23 |
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
|
|
|
92 |
"theme": theme,
|
93 |
"timestamp": datetime.now().isoformat()
|
94 |
}
|
95 |
+
|
96 |
+
if session["token"]:
|
97 |
+
db.child("stories").push({**story_data, "email": session["email"]})
|
98 |
+
else:
|
99 |
+
with open("story_logs.json", "a", encoding="utf-8") as f:
|
100 |
+
f.write(json.dumps(story_data) + "\n")
|
101 |
+
|
102 |
|
103 |
# ---------------- Kids Prompt (ChatPromptTemplate) ----------------
|
104 |
kids_prompt = ChatPromptTemplate.from_messages([
|
|
|
460 |
refresh_btn = gr.Button("π Load Stories")
|
461 |
refresh_btn.click(fn=refresh_dropdown, outputs=story_selector)
|
462 |
story_selector.change(fn=show_story_by_title, inputs=story_selector, outputs=story_output)
|
463 |
+
|
464 |
+
with gr.Tab("π Login"):
|
465 |
+
email_input = gr.Textbox(label="Email")
|
466 |
+
password_input = gr.Textbox(label="Password", type="password")
|
467 |
+
login_btn = gr.Button("Login")
|
468 |
+
login_msg = gr.Textbox(label="Status")
|
469 |
+
login_btn.click(login, inputs=[email_input, password_input], outputs=login_msg)
|
470 |
+
|
471 |
+
with gr.Tab("π Register"):
|
472 |
+
email_input2 = gr.Textbox(label="Email")
|
473 |
+
password_input2 = gr.Textbox(label="Password", type="password")
|
474 |
+
register_btn = gr.Button("Register")
|
475 |
+
register_msg = gr.Textbox(label="Status")
|
476 |
+
register_btn.click(register, inputs=[email_input2, password_input2], outputs=register_msg)
|
477 |
|
478 |
app.launch()
|