pi194046 commited on
Commit
141a839
·
1 Parent(s): 01b608d

deleting app

Browse files
Files changed (1) hide show
  1. streamlit_app.py +0 -122
streamlit_app.py DELETED
@@ -1,122 +0,0 @@
1
- import streamlit as st
2
- import requests
3
- import os
4
- import sqlite3
5
- import time
6
- import uuid
7
- import datetime
8
- import hashlib
9
-
10
-
11
- # FastAPI base URL
12
- #BASE_URL = "http://localhost:8000"
13
-
14
- import os
15
-
16
- API_URL=os.getenv("API_URL")
17
- API_TOKEN=os.getenv("API_TOKEN")
18
-
19
- BASE_URL=API_URL
20
-
21
- #API_URL = "https://api-inference.huggingface.co/models/your-username/your-private-model"
22
- headers = {"Authorization":f"Bearer {API_TOKEN}"}
23
-
24
- def query(payload):
25
- response = requests.post(API_URL, headers=headers, json=payload)
26
- return response.json()
27
-
28
- #data = query({"inputs": "Hello, how are you?"})
29
- #print(data)
30
-
31
- st.title("Performance Review Analyzer")
32
-
33
- def generate_unique_hash(filename: str, uuid: str) -> str:
34
- # Generate a UUID for the session or device
35
- device_uuid = uuid
36
-
37
- # Get the current date and time
38
- current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
39
-
40
- # Combine filename, current time, and UUID into a single string
41
- combined_string = f"{filename}-{current_time}-{device_uuid}"
42
-
43
- # Generate a hash using SHA256
44
- unique_hash = hashlib.sha256(combined_string.encode()).hexdigest()
45
-
46
- return unique_hash
47
-
48
- # Function to generate or retrieve a UUID from local storage
49
- uuid_script = """
50
- <script>
51
- if (!localStorage.getItem('uuid')) {
52
- localStorage.setItem('uuid', '""" + str(uuid.uuid4()) + """');
53
- }
54
- const uuid = localStorage.getItem('uuid');
55
- const streamlitUUIDInput = window.parent.document.querySelector('input[data-testid="stTextInput"][aria-label="UUID"]');
56
- if (streamlitUUIDInput) {
57
- streamlitUUIDInput.value = uuid;
58
- }
59
- </script>
60
- """
61
-
62
- ga_script = """
63
- <!-- Google tag (gtag.js) -->
64
- <script async src="https://www.googletagmanager.com/gtag/js?id=G-PWP4PRW5G5"></script>
65
- <script>
66
- window.dataLayer = window.dataLayer || [];
67
- function gtag(){dataLayer.push(arguments);}
68
- gtag('js', new Date());
69
-
70
- gtag('config', 'G-PWP4PRW5G5');
71
- </script>
72
- """
73
-
74
- # Add Google Analytics to the Streamlit app
75
- st.components.v1.html(ga_script, height=0, width=0)
76
-
77
- # Execute the JavaScript in the Streamlit app
78
- st.components.v1.html(uuid_script, height=0, width=0)
79
-
80
- # Store and display UUID in a non-editable text field using session state
81
- if 'uuid' not in st.session_state:
82
- st.session_state['uuid'] = str(uuid.uuid4())
83
-
84
- uuid_from_js = st.session_state['uuid']
85
-
86
- # Retrieve UUID from DOM
87
- if uuid_from_js is None:
88
- st.error("Unable to retrieve UUID from the browser.")
89
- else:
90
- # Display UUID in a non-editable text field
91
- st.text_input("Your UUID", value=uuid_from_js, disabled=True)
92
-
93
- uploaded_file = st.file_uploader("Upload your reviews CSV file", type=["csv"])
94
-
95
- if uploaded_file is not None:
96
- # Save uploaded file to FastAPI
97
- en1 = generate_unique_hash(uploaded_file.name, uuid_from_js)
98
- files = {"file": (en1, uploaded_file.getvalue(), "text/csv")}
99
- st.info("Calling model inference. Please wait...")
100
- response = requests.post(f"{BASE_URL}/upload/", files=files,headers=headers)
101
- print(response)
102
- if response.status_code == 200:
103
- st.info("Processing started. Please wait...")
104
-
105
- # Poll for completion
106
- while True:
107
- status_response = requests.get(f"{BASE_URL}/status/{en1}",headers=headers)
108
- if status_response.status_code == 200 and status_response.json()["status"] == "complete":
109
- st.success("File processed successfully.")
110
- download_response = requests.get(f"{BASE_URL}/download/{en1}",headers=headers)
111
-
112
- if download_response.status_code == 200:
113
- st.download_button(
114
- label="Download Processed File",
115
- data=download_response.content,
116
- file_name=f"processed_{en1}",
117
- mime="text/csv"
118
- )
119
- break
120
- time.sleep(2)
121
- else:
122
- st.error("Failed to upload file for processing.")