-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
75 lines (66 loc) · 2.06 KB
/
streamlit_app.py
File metadata and controls
75 lines (66 loc) · 2.06 KB
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
# streamlit_app.py
import streamlit as st
import asyncio
from main import poetry_agent, config, session
from agents import Runner
# Page config
st.set_page_config(
page_title="Poetry AI (Urdu + English)",
page_icon="🪶",
layout="centered",
initial_sidebar_state="collapsed"
)
# App Header
st.title("🪶 AI Poetry Companion")
st.markdown("""
<style>
body {
background-color: #f9f9f9;
}
.stTextInput textarea {
border: 2px solid #00b4d8;
border-radius: 10px;
}
.stButton>button {
background-color: #00b4d8;
color: white;
font-weight: bold;
border-radius: 10px;
}
</style>
""", unsafe_allow_html=True)
st.markdown("**Bilingual Poetry Generator (Urdu + English)**")
st.caption("Powered by Agentic AI with input/output guardrails 💡")
# Text input area
user_input = st.text_area(
"Enter your poetry theme or request:",
placeholder="e.g. Write a ghazal about rain in Urdu...",
height=150
)
# Chat memory area (optional)
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
# Generate button
if st.button("✨ Generate Poem"):
if not user_input.strip():
st.warning("Please enter something first.")
else:
with st.spinner("Composing your poem... 🎭"):
async def run_poetry():
result = await Runner.run(
poetry_agent,
input=user_input,
run_config=config,
session=session
)
return result.final_output or "Sorry, I couldn't compose that."
poem_output = asyncio.run(run_poetry())
st.session_state.chat_history.append(
{"user": user_input, "agent": poem_output}
)
# Display chat history
if st.session_state.chat_history:
for i, chat in enumerate(st.session_state.chat_history[::-1]):
with st.expander(f"🧍 You: {chat['user'][:30]}..."):
st.markdown(f"**🧍 You:** {chat['user']}")
st.markdown(f"**🤖 Agent:**\n{chat['agent']}")