Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import serial | |
import time | |
# Function to send SMS | |
def send_sms(port, phone_number, message): | |
try: | |
with serial.Serial(port, 9600, timeout=1) as ser: | |
ser.write(b'AT+CMGF=1\r') # Set SMS to text mode | |
time.sleep(1) | |
ser.write(f'AT+CMGS="{phone_number}"\r'.encode()) | |
time.sleep(1) | |
ser.write(f"{message}\x1A".encode()) # Send message with Ctrl+Z | |
time.sleep(3) | |
return ser.read_all().decode() | |
except Exception as e: | |
return str(e) | |
# Streamlit App | |
st.title("SMS Sender via EVO Device") | |
st.write("Upload an Excel file with phone numbers and messages.") | |
# File Upload | |
uploaded_file = st.file_uploader("Upload Excel File", type=["xlsx"]) | |
if uploaded_file: | |
# Load the Excel file | |
df = pd.read_excel(uploaded_file) | |
st.write("Preview of Uploaded File:") | |
st.dataframe(df) | |
# Check if the required columns exist | |
if "PhoneNumber" in df.columns and "Message" in df.columns: | |
st.write("Ready to send messages.") | |
# EVO device COM port | |
port = st.text_input("Enter EVO Device COM Port (e.g., COM3):", "") | |
if st.button("Send Messages"): | |
if port: | |
results = [] | |
for _, row in df.iterrows(): | |
phone_number = row["PhoneNumber"] | |
message = row["Message"] | |
response = send_sms(port, phone_number, message) | |
results.append({"PhoneNumber": phone_number, "Response": response}) | |
# Display Results | |
results_df = pd.DataFrame(results) | |
st.write("Results of SMS Sending:") | |
st.dataframe(results_df) | |
else: | |
st.error("Please enter the COM port.") | |
else: | |
st.error("The Excel file must contain 'PhoneNumber' and 'Message' columns.") | |
# Deployment Note | |
st.info("Deploy this app on Hugging Face Spaces using the Streamlit template.") |