Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
-
from gradio_client import Client
|
| 3 |
-
import tempfile
|
| 4 |
-
import os
|
| 5 |
-
HF_TOKEN= os.environ.get("HF_TOKEN", None)
|
| 6 |
|
| 7 |
-
# Function to make API prediction
|
| 8 |
-
def predict_image_description(uploaded_file):
|
| 9 |
-
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
| 10 |
-
temp_file.write(uploaded_file.read())
|
| 11 |
-
temp_file.close()
|
| 12 |
-
client = Client("https://ashrafb-imca-arabicgradioapi.hf.space/", hf_token=HF_TOKEN)
|
| 13 |
-
result = client.predict(temp_file.name, api_name="/predict")
|
| 14 |
-
return result
|
| 15 |
|
| 16 |
-
|
| 17 |
-
st.markdown('<p style="color:crimson;text-align:center;font-size:30px;">Aiconvert.online Image Description</p>', unsafe_allow_html=True)
|
| 18 |
-
hide_streamlit_style = """
|
| 19 |
-
<style>
|
| 20 |
-
#MainMenu {visibility: hidden;}
|
| 21 |
-
footer {visibility: hidden;}
|
| 22 |
-
</style>
|
| 23 |
-
"""
|
| 24 |
-
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
| 25 |
-
st.write("Upload an image and click the button to get a description!")
|
| 26 |
-
|
| 27 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 28 |
-
|
| 29 |
-
if uploaded_file is not None:
|
| 30 |
-
st.image(uploaded_file, caption="Uploaded Image.", use_column_width=True)
|
| 31 |
-
st.write("")
|
| 32 |
-
|
| 33 |
-
# Button for generating description
|
| 34 |
-
if st.button("Generate Description"):
|
| 35 |
-
# Display loading indicator
|
| 36 |
-
with st.spinner("Generating..."):
|
| 37 |
-
# Make API prediction
|
| 38 |
-
description = predict_image_description(uploaded_file)
|
| 39 |
-
st.write(f"Description: {description}")
|
|
|
|
| 1 |
+
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
exec(os.environ.get('API'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|