agentharbor commited on
Commit
2586d92
·
verified ·
1 Parent(s): b64b9ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -1
app.py CHANGED
@@ -9,6 +9,53 @@ from streaming import stream_to_gradio
9
  from huggingface_hub import login
10
  from gradio.data_classes import FileData
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  login(os.getenv("HUGGINGFACEHUB_API_TOKEN"))
13
 
14
  llm_engine = HfEngine("meta-llama/Meta-Llama-3.1-70B-Instruct")
@@ -61,10 +108,14 @@ def interact_with_agent(file_input, additional_notes):
61
  - Columns with dtypes:
62
  {data_file.dtypes}"""
63
 
 
 
 
 
64
  prompt = base_prompt.format(structure_notes=data_structure_notes)
65
 
66
  if additional_notes and len(additional_notes) > 0:
67
- prompt += "\nAdditional notes on the data:\n" + additional_notes
68
 
69
  messages = [gr.ChatMessage(role="user", content=prompt)]
70
  yield messages + [
 
9
  from huggingface_hub import login
10
  from gradio.data_classes import FileData
11
 
12
+ import google.generativeai as genai
13
+ os.environ["API_KEY"] = 'AIzaSyB8Hj4oCbBH9arFWSgybHnbpZLs2sa4p1w'
14
+ os.environ["GOOGLE_API_KEY"] = 'AIzaSyBjuYTWBlHg4W2wGaQCKKbigz6deZuLUJc'
15
+ genai.configure(api_key=os.environ["API_KEY"])
16
+
17
+ generation_config = {
18
+ "temperature": 0.2,
19
+ "top_p": 0.95,
20
+ "top_k": 0,
21
+ "max_output_tokens": 8192,
22
+ }
23
+
24
+ safety_settings = [
25
+ {
26
+ "category": "HARM_CATEGORY_HARASSMENT",
27
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
28
+ },
29
+ {
30
+ "category": "HARM_CATEGORY_HATE_SPEECH",
31
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
32
+ },
33
+ {
34
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
35
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
36
+ },
37
+ {
38
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
39
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
40
+ },
41
+ ]
42
+
43
+ context = "You are an expert data analyst who can provide guidance around what needs to be analyzed from a dataset by just looking at metadata."
44
+ system_instruction = context
45
+ import re
46
+
47
+ model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest",
48
+ generation_config=generation_config,
49
+ system_instruction=system_instruction,
50
+ safety_settings=safety_settings)
51
+
52
+
53
+ def model_response(text):
54
+ #model = genai.GenerativeModel('gemini-pro')
55
+ response = model.generate_content(text)
56
+ return response.text
57
+
58
+
59
  login(os.getenv("HUGGINGFACEHUB_API_TOKEN"))
60
 
61
  llm_engine = HfEngine("meta-llama/Meta-Llama-3.1-70B-Instruct")
 
108
  - Columns with dtypes:
109
  {data_file.dtypes}"""
110
 
111
+ enhanced_notes = model_response(f'''Given the metadata of the dataset {data_structure_notes} and the context provided by the user {additional_notes}, figure out the
112
+ domain this dataset belongs to. Now assume the role of an expert data analyst in this domain and generate instructions/commentary that will help a large language model analyze
113
+ this dataset.''')
114
+
115
  prompt = base_prompt.format(structure_notes=data_structure_notes)
116
 
117
  if additional_notes and len(additional_notes) > 0:
118
+ prompt += "\nAdditional notes on the data:\n" + enhanced_notes
119
 
120
  messages = [gr.ChatMessage(role="user", content=prompt)]
121
  yield messages + [