Spaces:
Runtime error
Runtime error
import streamlit as st | |
import requests | |
import json | |
import time | |
st.title("Transaction Summarizer") | |
# Input for submitting new transactions | |
new_transactions = st.text_area("Enter your transactions (comma-separated)").split(',') | |
new_transactions = [i.strip() for i in new_transactions if i.strip()] | |
# Submit button for new transactions | |
if st.button("Submit New Transactions"): | |
url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/run" | |
headers = { | |
'Content-Type': 'application/json', | |
'Authorization': 'API_KEY' | |
} | |
data = { | |
'input': { | |
'transaction': new_transactions | |
} | |
} | |
json_data = json.dumps(data) | |
try: | |
# Send POST request to start processing | |
response = requests.post(url, headers=headers, data=json_data) | |
response.raise_for_status() # Raise an error for bad status codes | |
# Parse response to get job ID | |
result = response.json() | |
job_id = result['id'] | |
st.write(f"New Job ID: {job_id}") | |
# Keep checking status until it's no longer 'IN_QUEUE' | |
status_url = f"https://api.runpod.ai/v2/0wnm75vx5o77s1/status:{job_id}" | |
status = "IN_QUEUE" | |
while status == "IN_QUEUE": | |
status_response = requests.get(status_url, headers=headers) | |
status_data = status_response.json() | |
status = status_data.get('status', '') | |
time.sleep(5) # Adjust interval as needed | |
st.write(f"Current status: {status}") | |
# Once status changes, display final status | |
st.write("Final status:", status_data) | |
except requests.exceptions.RequestException as e: | |
st.error(f"An error occurred: {e}") | |
# Input and button for fetching status or result by job ID | |
st.subheader("Fetch Status or Result by Job ID") | |
job_id_input = st.text_input("Enter Job ID") | |
if st.button("Fetch Status or Result"): | |
if job_id_input: | |
try: | |
status_url = f"https://api.runpod.ai/v2/0wnm75vx5o77s1/status:{job_id_input}" | |
headers = { | |
'Authorization': 'API_KEY' | |
} | |
# Fetch status or result based on job ID | |
status_response = requests.get(status_url, headers=headers) | |
status_data = status_response.json() | |
# Display status or result | |
st.write("Status or Result:", status_data) | |
except requests.exceptions.RequestException as e: | |
st.error(f"An error occurred: {e}") | |
else: | |
if st.button("Reset"): | |
st.text_area("Enter your transactions (comma-separated)", value="") | |