Spaces:
Sleeping
Sleeping
Commit
·
c346bb7
1
Parent(s):
96c3529
fix
Browse files
app.py
CHANGED
@@ -1,11 +1,15 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# API URL and headers
|
5 |
API_URL = "https://pllfc7e5i0rujahy.us-east-1.aws.endpoints.huggingface.cloud"
|
6 |
headers = {
|
7 |
"Accept": "application/json",
|
8 |
-
"Authorization":
|
9 |
"Content-Type": "application/json"
|
10 |
}
|
11 |
|
@@ -14,14 +18,32 @@ def query(payload):
|
|
14 |
response = requests.post(API_URL, headers=headers, json=payload)
|
15 |
return response.json()
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# Streamlit app layout
|
18 |
st.title("API Query App")
|
19 |
st.write("This app allows you to query the API and retrieve responses.")
|
20 |
|
21 |
-
user_input = st.text_input("Enter your input:"
|
|
|
|
|
|
|
22 |
|
|
|
23 |
if st.button("Submit"):
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
output = query({"inputs": user_input, "parameters": {}})
|
26 |
st.success("Response received!")
|
27 |
-
st.
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
+
from PIL import Image
|
4 |
+
import pytesseract
|
5 |
+
|
6 |
+
api_key = os.getenv("HFBearer")
|
7 |
|
8 |
# API URL and headers
|
9 |
API_URL = "https://pllfc7e5i0rujahy.us-east-1.aws.endpoints.huggingface.cloud"
|
10 |
headers = {
|
11 |
"Accept": "application/json",
|
12 |
+
"Authorization": api_key, # Replace with your actual token
|
13 |
"Content-Type": "application/json"
|
14 |
}
|
15 |
|
|
|
18 |
response = requests.post(API_URL, headers=headers, json=payload)
|
19 |
return response.json()
|
20 |
|
21 |
+
# Function to extract text from image
|
22 |
+
def extract_text_from_image(image_path):
|
23 |
+
image = Image.open(image_path)
|
24 |
+
text = pytesseract.image_to_string(image)
|
25 |
+
return text
|
26 |
+
|
27 |
# Streamlit app layout
|
28 |
st.title("API Query App")
|
29 |
st.write("This app allows you to query the API and retrieve responses.")
|
30 |
|
31 |
+
user_input = st.text_input("Enter your input:")
|
32 |
+
|
33 |
+
# File uploader for the image
|
34 |
+
uploaded_image = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
35 |
|
36 |
+
# Submit button
|
37 |
if st.button("Submit"):
|
38 |
+
if uploaded_image is not None:
|
39 |
+
with st.spinner("Extracting text from image..."):
|
40 |
+
# Extract text from the uploaded image
|
41 |
+
extracted_text = extract_text_from_image(uploaded_image)
|
42 |
+
st.write("Extracted text from image:")
|
43 |
+
st.write(extracted_text)
|
44 |
+
|
45 |
+
with st.spinner("Fetching response from API..."):
|
46 |
+
# Query the API with user input
|
47 |
output = query({"inputs": user_input, "parameters": {}})
|
48 |
st.success("Response received!")
|
49 |
+
st.write(output[0]["generated_text"]) # Display the response
|