|
|
import streamlit as st |
|
|
import requests |
|
|
import base64 |
|
|
|
|
|
|
|
|
API_URL = "https://dvorakinnovationai-revel-rizz-api.hf.space/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.") |
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Upload an image (JPG/PNG)", type=["jpg", "jpeg", "png"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
available_tones = ["formal", "casual", "friendly", "professional", "humorous"] |
|
|
tones = st.multiselect("Select tones (optional)", available_tones) |
|
|
|
|
|
|
|
|
if st.button("Generate Reply"): |
|
|
if uploaded_file is None: |
|
|
st.error("β οΈ Please upload an image first.") |
|
|
|
|
|
else: |
|
|
try: |
|
|
|
|
|
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)}") |
|
|
|