jacket-frontend / app.py
Hammad712's picture
Update app.py
5ec36dc verified
import streamlit as st
import requests
import json
# Define the FastAPI URL
FASTAPI_URL = "https://hammad712-jacket-generation.hf.space"
st.title("AI-Powered Mock-Up Generator")
# Initialize session state
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
# Sidebar for new chat and download options
with st.sidebar:
st.subheader("Options")
if st.button("Start New Chat"):
with st.spinner("Starting new chat..."):
requests.post(f"{FASTAPI_URL}/new_chat/")
st.session_state.chat_history = []
st.success("New chat session started!")
# Function to send user input to FastAPI
def send_question(question):
with st.spinner("Processing..."):
response = requests.post(f"{FASTAPI_URL}/conversation/", json={"question": question})
if response.status_code == 200:
return response.json()["response"]
else:
return f"Error: {response.status_code} - {response.text}"
# User input
question = st.text_input("Ask something about your AI-powered mock-up:")
if st.button("Send"):
if question:
response = send_question(question)
st.session_state.chat_history.append(("You:", question))
st.session_state.chat_history.append(("AI:", response))
else:
st.warning("Please enter a question.")
# Display chat history
st.subheader("Chat History")
for role, msg in st.session_state.chat_history:
st.write(f"**{role}** {msg}")