Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,14 @@ import pandas as pd
|
|
| 5 |
from docx import Document
|
| 6 |
import time
|
| 7 |
import re
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
#=====
|
| 12 |
#Payment type
|
| 13 |
manual_payment_type="""
|
|
@@ -98,6 +103,35 @@ def generate_html(llm_response):
|
|
| 98 |
html+="<tr><td>"+line+"</td></tr>"
|
| 99 |
return html
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
def loop_function(df):
|
| 103 |
text = "<hr>"
|
|
@@ -153,7 +187,7 @@ def loop_function(df):
|
|
| 153 |
if i == 1:
|
| 154 |
try:
|
| 155 |
rr = generate_response(manual_rules, proposal_details)
|
| 156 |
-
|
| 157 |
text += """
|
| 158 |
<div style="color: white !important; background: #006400 !important; padding: 10px; font-size: 14px;">
|
| 159 |
|
|
@@ -184,8 +218,9 @@ def check_compliance_tech(file):
|
|
| 184 |
yield "Coming Soon"
|
| 185 |
else:
|
| 186 |
yield "Unsupported file format"
|
| 187 |
-
#================================================Gradio==================
|
| 188 |
|
|
|
|
|
|
|
| 189 |
css = """
|
| 190 |
#admin-file .label, #admin-file label { color: #FFFFFF !important; font-size: 16px !important; }
|
| 191 |
#admin-file { background-color: #000000 !important; }
|
|
|
|
| 5 |
from docx import Document
|
| 6 |
import time
|
| 7 |
import re
|
| 8 |
+
from huggingface_hub import hf_hub_download
|
| 9 |
+
from huggingface_hub import HfApi, login
|
| 10 |
+
from datetime import datetime
|
| 11 |
|
| 12 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 13 |
+
api = HfApi(token=os.getenv("HF_TOKEN"))
|
| 14 |
+
repo_id = "manabb/nrl"
|
| 15 |
+
file_path_in_repo="LLMLogs.txt"
|
| 16 |
#=====
|
| 17 |
#Payment type
|
| 18 |
manual_payment_type="""
|
|
|
|
| 103 |
html+="<tr><td>"+line+"</td></tr>"
|
| 104 |
return html
|
| 105 |
|
| 106 |
+
#================================================Gradio==================
|
| 107 |
+
|
| 108 |
+
def update_log(newRecords):
|
| 109 |
+
# Download existing, append, re-upload
|
| 110 |
+
|
| 111 |
+
try:
|
| 112 |
+
# Download current version
|
| 113 |
+
downloaded_path = hf_hub_download(
|
| 114 |
+
repo_id=repo_id,
|
| 115 |
+
filename=file_path_in_repo,
|
| 116 |
+
repo_type="dataset"
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
# Append new line
|
| 120 |
+
with open(downloaded_path, 'a', encoding='utf-8') as f:
|
| 121 |
+
f.write("\n"+newRecords+"\n")
|
| 122 |
+
|
| 123 |
+
# Re-upload (overwrites)
|
| 124 |
+
api.upload_file(
|
| 125 |
+
path_or_fileobj=downloaded_path,
|
| 126 |
+
path_in_repo=file_path_in_repo,
|
| 127 |
+
repo_id=repo_id,
|
| 128 |
+
repo_type="dataset",
|
| 129 |
+
commit_message="Append new log entry"
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
except Exception:
|
| 133 |
+
print("File not found - created new")
|
| 134 |
+
#==============================
|
| 135 |
|
| 136 |
def loop_function(df):
|
| 137 |
text = "<hr>"
|
|
|
|
| 187 |
if i == 1:
|
| 188 |
try:
|
| 189 |
rr = generate_response(manual_rules, proposal_details)
|
| 190 |
+
update_log("\n"+datetime.now().isoformat()+"\n"+rr)
|
| 191 |
text += """
|
| 192 |
<div style="color: white !important; background: #006400 !important; padding: 10px; font-size: 14px;">
|
| 193 |
|
|
|
|
| 218 |
yield "Coming Soon"
|
| 219 |
else:
|
| 220 |
yield "Unsupported file format"
|
|
|
|
| 221 |
|
| 222 |
+
|
| 223 |
+
#================================
|
| 224 |
css = """
|
| 225 |
#admin-file .label, #admin-file label { color: #FFFFFF !important; font-size: 16px !important; }
|
| 226 |
#admin-file { background-color: #000000 !important; }
|