File size: 1,606 Bytes
e904228
96c3529
c346bb7
 
 
fcbfa92
 
c346bb7
96c3529
 
 
 
 
c346bb7
96c3529
e904228
 
96c3529
 
 
 
e904228
c346bb7
 
 
 
 
 
96c3529
 
 
e904228
c346bb7
 
 
 
e904228
c346bb7
96c3529
c346bb7
 
 
 
 
 
 
 
 
96c3529
 
c346bb7
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
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