-
Notifications
You must be signed in to change notification settings - Fork 0
/
evison.py
81 lines (63 loc) · 2.55 KB
/
evison.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from __future__ import print_function
import streamlit as st
import tempfile
from roboflow import Roboflow
from PIL import Image
import africastalking
rf = Roboflow(api_key="aQONY7aSjUN7H1sSqu0s")
project = rf.workspace().project("e-waste-detection-model")
model = project.version(3).model
# Page configuration
st.set_page_config(page_title="e vision", page_icon="🚮")
#########################################################
user_phone = st.text_input("Enter Your Phone Number: ")
# Display the entered text
if user_phone:
st.write(f"You entered: {user_phone}")
class AIRTIME:
def __init__(self):
# Set your app credentials
self.username = "mild.ke"
self.api_key = "daae7b33a138c168292fbe863cd135d3b33b5f768639cef6f70d6ba141e0d8b1"
# Initialize the SDK
africastalking.initialize(self.username, self.api_key)
# Get the airtime service
self.airtime = africastalking.Airtime
def send(self):
# Set phone_number in international format
phone_number = user_phone
# Set The 3-Letter ISO currency code and the amount
amount ="01.00"
currency_code = "KES"
try:
# That's it hit send and we'll take care of the rest
responses = self.airtime.send(phone_number=phone_number, amount=amount, currency_code=currency_code)
print (responses)
except Exception as e:
print ("Encountered an error while sending airtime:%s" %str(e))
####################################
# Reward User
tokens = 0
st.title("e-vision")
st.markdown("Detect E-WASTE using AI")
uploaded_file = st.file_uploader(label="Upload Image", type=["jpg", "jpeg", "png"], key="1")
if uploaded_file is not None:
# Save the uploaded image to a temporary location
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_path = temp_file.name
temp_file.write(uploaded_file.read())
# Perform prediction on the saved image
try:
st.spinner("Processing.......")
prediction = model.predict(temp_path, confidence=40, overlap=30)
tokens += 5
st.success(f"Tokens = {tokens}")
AIRTIME().send()
except:
st.info("Failed, Upload another image")
# Save the prediction image manually
prediction_image_path = "prediction.jpg"
prediction.save(prediction_image_path)
# Display the prediction result using PIL
prediction_image = Image.open(prediction_image_path)
st.image(prediction_image, caption="Prediction Image", use_column_width=True)