Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
# Define the FastAPI URL
|
| 6 |
+
FASTAPI_URL = "http://127.0.0.1:8000"
|
| 7 |
+
|
| 8 |
+
st.title("AI-Powered Mock-Up Generator")
|
| 9 |
+
|
| 10 |
+
# Initialize session state
|
| 11 |
+
if "chat_history" not in st.session_state:
|
| 12 |
+
st.session_state.chat_history = []
|
| 13 |
+
|
| 14 |
+
# Sidebar for new chat and download options
|
| 15 |
+
with st.sidebar:
|
| 16 |
+
st.subheader("Options")
|
| 17 |
+
if st.button("Start New Chat"):
|
| 18 |
+
with st.spinner("Starting new chat..."):
|
| 19 |
+
requests.post(f"{FASTAPI_URL}/new_chat/")
|
| 20 |
+
st.session_state.chat_history = []
|
| 21 |
+
st.success("New chat session started!")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# Function to send user input to FastAPI
|
| 25 |
+
def send_question(question):
|
| 26 |
+
with st.spinner("Processing..."):
|
| 27 |
+
response = requests.post(f"{FASTAPI_URL}/conversation/", json={"question": question})
|
| 28 |
+
if response.status_code == 200:
|
| 29 |
+
return response.json()["response"]
|
| 30 |
+
else:
|
| 31 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 32 |
+
|
| 33 |
+
# User input
|
| 34 |
+
question = st.text_input("Ask something about your AI-powered mock-up:")
|
| 35 |
+
|
| 36 |
+
if st.button("Send"):
|
| 37 |
+
if question:
|
| 38 |
+
response = send_question(question)
|
| 39 |
+
st.session_state.chat_history.append(("You:", question))
|
| 40 |
+
st.session_state.chat_history.append(("AI:", response))
|
| 41 |
+
else:
|
| 42 |
+
st.warning("Please enter a question.")
|
| 43 |
+
|
| 44 |
+
# Display chat history
|
| 45 |
+
st.subheader("Chat History")
|
| 46 |
+
for role, msg in st.session_state.chat_history:
|
| 47 |
+
st.write(f"**{role}** {msg}")
|