Spaces:
Sleeping

tagging / app.py
zeisha's picture
openai/gpt-oss-120b
68ceb08
Raw History Blame Contribute Delete
1.1 kB
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()