-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
70 lines (56 loc) · 2.04 KB
/
app.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import ollama
import pandas as pd
#def (prompt: str, file:)
# Set pwd same as app.py
script_dir = os.path.dirname(__file__)
os.chdir(script_dir)
# Ollama model, error handling
model = 'llama3.2:3b'
try:
ollama.chat(model)
except ollama.ResponseError as e:
print('Error:', e.error)
if e.status_code == 404:
ollama.pull(model)
# Read the CSV, error handling
df = pd.read_csv('data.csv')
try:
df = pd.read_csv('data.csv')
except FileNotFoundError:
print("The file does not exist.")
except pd.errors.EmptyDataError:
print("The file is empty.")
except pd.errors.ParserError:
print("Error parsing the file. Please check the file format.")
# Column prompt_var to a list
prompt_var_list = df["prompt_var"].tolist()
##### ================================================================== #####
# #
# Edit your base prompt below #
# Each item in data.csv will sit in a new line under the base prompt #
# #
#### =================================================================== #####
# Base prompt
prompt = """
You are a helpful assistant expert in branding. Create a brand name using the following keyword. It must be easy to pronounce and easy to remember.
Provide the brand name only.
Keyword:\n
"""
responses = [] # Create an empty list to store the responses
# Loop variable through LLM
for item in prompt_var_list:
response = ollama.chat(model=model, messages=[
{
'role': 'user',
'content': f"""
{prompt}
{item}
""",
},
])
responses.append(response['message']['content']) # Append the response to the list
#print(response['message']['content'])
# Save responses list as csv
responses = pd.DataFrame(responses, columns=['responses']) # Convert list to DataFrame
responses.to_csv('responses.csv', index=False)