File size: 1,714 Bytes
8a3759d
7c6aa59
 
ac000e9
7c6aa59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ac000e9
7c6aa59
 
 
ac000e9
7c6aa59
ac000e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c6aa59
 
 
ac000e9
7c6aa59
 
 
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
import streamlit as st
import requests
import json
import time

st.title("Transaction Summarizer")

transactions = st.text_area("Enter your transactions (comma-separated)").split(',')
transactions = [i.strip() for i in transactions if i.strip()]

if st.button("Submit"):
    url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/run"
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'API_KEY'
    }
    data = {
        'input': {
            'transaction': 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"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 result
        st.write("Final status:", 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="")