File size: 1,713 Bytes
84d64f1
 
 
 
 
4f85312
 
84d64f1
 
 
23c0787
 
84d64f1
 
 
 
 
 
 
 
 
 
 
 
 
 
4f85312
84d64f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)}")