File size: 1,102 Bytes
eaf68f0 d534b22 adcfa2b 8ef74e1 eaf68f0 68ceb08 eaf68f0 8ef74e1 adcfa2b e9a11bf adcfa2b eaf68f0 d534b22 adcfa2b eaf68f0 8ef74e1 2e7f431 8ef74e1 d534b22 | 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 | import os
from Tagger import Tagger
import pandas as pd
import spaces
from pathlib import Path
import gradio as gr
model = "openai/gpt-oss-120b"
tagger = Tagger(model_name=model)
folder_path = "passages/"
files = [
f for f in os.listdir(folder_path)
if os.path.isfile(os.path.join(folder_path, f))
]
OUT_DIR = Path("outputs")
OUT_DIR.mkdir(exist_ok=True)
@spaces.GPU
def produce_result():
result = {}
j = 1
for file in files:
print(j)
j += 1
path = "passages/" + file
with open(path, "r", encoding="utf-8") as f:
text = f.read()
assigned_tag = tagger.tag(text)
result[file] = assigned_tag
return result
def make_csv():
result = produce_result()
df = pd.DataFrame(
[(k, v) for k, v in result.items()],
columns=["file_name", "tags"]
)
out_path = OUT_DIR / "Llama_3_1_8B_Instruct_75_100.csv"
df.to_csv(out_path, index=False) # write to disk
return str(out_path)
demo = gr.Interface(fn=make_csv, inputs=None, outputs=gr.File(label="Download CSV"))
demo.launch()
|