ZamaKlinik / app.py
lukalafaye's picture
fix
fcbfa92
raw
history blame
1.61 kB
import streamlit as st
import requests
from PIL import Image
import pytesseract
import os
api_key = os.getenv("HFBearer")
# API URL and headers
API_URL = "https://pllfc7e5i0rujahy.us-east-1.aws.endpoints.huggingface.cloud"
headers = {
"Accept": "application/json",
"Authorization": api_key, # Replace with your actual token
"Content-Type": "application/json"
}
# Function to query the API
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
# Function to extract text from image
def extract_text_from_image(image_path):
image = Image.open(image_path)
text = pytesseract.image_to_string(image)
return text
# Streamlit app layout
st.title("API Query App")
st.write("This app allows you to query the API and retrieve responses.")
user_input = st.text_input("Enter your input:")
# File uploader for the image
uploaded_image = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
# Submit button
if st.button("Submit"):
if uploaded_image is not None:
with st.spinner("Extracting text from image..."):
# Extract text from the uploaded image
extracted_text = extract_text_from_image(uploaded_image)
st.write("Extracted text from image:")
st.write(extracted_text)
with st.spinner("Fetching response from API..."):
# Query the API with user input
output = query({"inputs": user_input, "parameters": {}})
st.success("Response received!")
st.write(output[0]["generated_text"]) # Display the response