Upload fastchatrana.py
Browse files- fastchatrana.py +29 -0
fastchatrana.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import pandas as pd
|
3 |
+
from fschat import ChatModel, ChatSession
|
4 |
+
from fschat.utils import download_model
|
5 |
+
|
6 |
+
# Replace 'lm-sys/FastChat' with the actual path to the model
|
7 |
+
model_path = download_model("lm-sys/fastchat-t5-3b-v1.0")
|
8 |
+
|
9 |
+
model = ChatModel.load(model_path)
|
10 |
+
model.to("cpu") # run the model on CPU
|
11 |
+
model.eval()
|
12 |
+
|
13 |
+
session = ChatSession.new_session(model)
|
14 |
+
|
15 |
+
def extract_dates(model, text):
|
16 |
+
with torch.no_grad():
|
17 |
+
# User utterances are added with 'user:' prefix and the 'extract dates:' task
|
18 |
+
session.add_utterance(f"user:extract dates: {text}")
|
19 |
+
response = session.get_response()
|
20 |
+
return response.text
|
21 |
+
|
22 |
+
# Load the CSV file
|
23 |
+
df = pd.read_csv('input.csv')
|
24 |
+
|
25 |
+
# Apply the function to each row
|
26 |
+
df['Extracted_Dates'] = df['OBJECT_NAME'].apply(lambda x: extract_dates(model, x))
|
27 |
+
|
28 |
+
# Save the results to a new CSV file
|
29 |
+
df.to_csv('output.csv', index=False)
|