import streamlit as st import requests import base64 # FastAPI endpoint API_URL = "https://dvorakinnovationai-revel-rizz-api.hf.space/api/reply-generator" # API_URL = "http://127.0.0.1:8000//api/reply-generator" st.set_page_config(page_title="Reply Generator", page_icon="💬", layout="centered") st.title("Reply Generator") st.write("Upload image of chat , ask a question, and get AI-powered replies.") # Upload image uploaded_file = st.file_uploader("Upload an image (JPG/PNG)", type=["jpg", "jpeg", "png"]) # User query input # Tones (multi-select) available_tones = ["formal", "casual", "friendly", "professional", "humorous"] tones = st.multiselect("Select tones (optional)", available_tones) # Button to trigger API if st.button("Generate Reply"): if uploaded_file is None: st.error("⚠️ Please upload an image first.") else: try: # Convert image to base64 image_bytes = uploaded_file.read() image_base64 = base64.b64encode(image_bytes).decode("utf-8") payload = { "image_base64": image_base64, "tones": tones if tones else None, } with st.spinner("⏳ Generating reply..."): response = requests.post(API_URL, json=payload) if response.status_code == 200: data = response.json() st.success("✅ Reply generated successfully!") st.write("### Response:") st.json(response.json()) else: st.error(f"❌ Error: {response.status_code} - {response.text}") except Exception as e: st.error(f"🚨 An error occurred: {str(e)}")