Spaces:
Runtime error
Runtime error
File size: 2,980 Bytes
b26b37f 0308164 bf4a0ea 0308164 b26b37f bf4a0ea a9b3ce0 b26b37f bf4a0ea 0308164 bf4a0ea 0308164 bf4a0ea 0308164 bf4a0ea a9b3ce0 0308164 a9b3ce0 0308164 a9b3ce0 0308164 a9b3ce0 b26b37f 0308164 a9b3ce0 0308164 b26b37f 0308164 a9b3ce0 b26b37f a9b3ce0 0308164 a9b3ce0 0308164 a9b3ce0 b26b37f a9b3ce0 b26b37f a9b3ce0 b26b37f 0308164 a9b3ce0 0308164 a9b3ce0 0308164 a9b3ce0 b26b37f a9b3ce0 b26b37f 0308164 a9b3ce0 b26b37f |
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 82 83 84 85 |
import gradio as gr
import gspread
import os
from google.oauth2 import service_account
from twilio.rest import Client
# Google Sheets Setup
scope = [
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/drive"
]
private_key = os.environ["PRIVATE_KEY"].replace('\\n', '\n')
credentials = service_account.Credentials.from_service_account_info({
"type": "service_account",
"project_id": "varahaa-farmers",
"private_key_id": "f48da20518b3a08df328b6d07006b35472445e5b",
"private_key": private_key,
"client_email": "[email protected]",
"client_id": "113471167964788057428",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/huggingface-bot%40varahaa-farmers.iam.gserviceaccount.com"
}, scopes=scope)
gc = gspread.authorize(credentials)
sheet = gc.open("Varahaa Farmer Verification").sheet1
# Rest of your Twilio and Gradio code...
creds = ServiceAccountCredentials.from_json_keyfile_dict(creds_dict, scope)
client = gspread.authorize(creds)
sheet = client.open("Varahaa Farmer Verification").sheet1
# Initialize Twilio
twilio_client = Client(os.environ["ACf8b3539472179ac15fb46939a02bb802"], os.environ["297cffb015681887dade0d42180332b9"])
# Load NLP model
qa_pipeline = pipeline("question-answering", model="bert-base-uncased")
def get_farmer_data(phone):
try:
return sheet.find(phone)
except:
return None
def verify_farmer(phone, query):
farmer = get_farmer_data(phone)
if not farmer:
return "Farmer not found"
row = sheet.row_values(farmer.row)
if "name" in query.lower():
return f"Name: {row[1]}"
elif "survey" in query.lower():
return f"Survey: {row[2]}"
elif "area" in query.lower():
return f"Farm Area: {row[4]} acres"
else:
return "Available queries: name, survey, area"
def send_questionnaire(phone):
try:
message = twilio_client.messages.create(
body="🌾 Please verify your details:\n1. Is your name correct?\n2. Farm area?",
from_='whatsapp:+14155238886',
to=f'whatsapp:{phone}'
)
return "Questionnaire sent!"
except Exception as e:
return f"Error: {str(e)}"
with gr.Blocks() as demo:
gr.Markdown("# Varahaa Farmer Verification")
phone = gr.Textbox(label="Phone Number")
query = gr.Dropdown(["Name Check", "Survey Status", "Farm Area"], label="Select Query")
output = gr.Textbox(label="Result")
verify_btn = gr.Button("Verify")
send_btn = gr.Button("Send Questionnaire")
verify_btn.click(fn=verify_farmer, inputs=[phone, query], outputs=output)
send_btn.click(fn=send_questionnaire, inputs=phone, outputs=output)
demo.launch() |