heymenn commited on
Commit
78d5505
·
verified ·
1 Parent(s): 53eeb1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -3
app.py CHANGED
@@ -1,7 +1,113 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ from groq import Groq
4
 
5
+ def excel_to_csv(fi):
6
+ df = pd.read_excel(fi)
7
 
8
+ columns = ';'.join(df.columns)
9
+
10
+ df = df.to_csv(path_or_buf = "here2.csv")
11
+
12
+ return gr.Dropdown(choices=columns, label="Columns of the file", multiselect=True, allow_custom_value=True), "here2.csv"
13
+
14
+ def text_to_neoj(rm, cm):
15
+ prompt = """
16
+
17
+ Here is a random Neo4J database with additionnal informations in '#' :
18
+
19
+ (d:Document {URL: string (#contains the url of the document), type: string (#contains the type of the document), Description: string (#contains the description of the document)} -[:TALKS_ABOUT]-> (t: Topic {title: string (#contains the title of the topic), description: string (#contains the description of the topic)}) <-[:INTERESTED_BY]- (e: Expert {name: string (#contains the name of the expert)};
20
+
21
+
22
+ (s:Solution {url: string (#contains the url of the document the solution refers to), description: string (#contains the description of the solution})-[:SOLUTION_OF]->(d)
23
+ (p:Problem {url: string (#contains the url of the document the problem refers to), description: string (#contains the description of the problem})-[:PROBLEM_OF]->(d);
24
+
25
+ ---
26
+ Here is a exemple of a Cypher script for this data batase:
27
+
28
+ //KeyIssues
29
+ LOAD CSV WITH HEADERS FROM 'file:///dataKeyIssues.csv' AS row
30
+ FIELDTERMINATOR ';'
31
+ WITH row WHERE row.Expert IS NOT NULL AND row.Problems IS NULL
32
+ WITH row, split(replace(row.Description,", This topic","This topic"), 'This topic') as Descriptions, split(row.Topic, ',') as Topics, split(row.Expert, ',') AS Experts, split(row.Score, ',') as Score
33
+
34
+ MERGE (dd:Document {uri: row.Document, description: row.`Key Issue`, type: "TR"})
35
+
36
+ FOREACH (i IN RANGE(0, size(Descriptions) - 2) |
37
+ MERGE (t:Topic {name: trim(Topics[i]), description: trim(Descriptions[i+1])})
38
+ MERGE (dd)-[r:TALKS_ABOUT{}]->(t)
39
+ ON CREATE set r.score = Score[i]
40
+ ON MATCH SET
41
+ r.score = CASE WHEN Score[i] > r.score
42
+ THEN Score[i]
43
+ ELSE r.score END
44
+ MERGE (e:Expert {name: trim(Experts[i])})
45
+ MERGE (e)-[:INTERESTED_BY]->(t)
46
+ );
47
+
48
+ LOAD CSV WITH HEADERS FROM 'file:///dataKeyIssues.csv' AS row
49
+ FIELDTERMINATOR ';'
50
+ WITH row WHERE row.Problems IS NOT NULL
51
+ WITH row, split(replace(row.Description,", This topic","This topic"), 'This topic') as Descriptions, split(row.Topic, ',') as Topics
52
+
53
+ MERGE (dd:Document {uri: row.Document, keyIssues: row.`Key Issue`, type: "TR"})
54
+ MERGE (p:Problem {description: row.Problems})
55
+ MERGE (p)-[:PROBLEM_OF]->(dd)
56
+ ---
57
+ With the first line of a CSV file, provide me a Neo4J Cypher script which implement the csv file in the database. Here are some remarks about this file : %s .Only provide a script based on the data given in the CSV file:
58
+
59
+ First line = %s
60
+ """ % (rm,cm)
61
+
62
+ messages = [
63
+ {
64
+ "role": "system",
65
+ "content": f"You are a helpful assistant. Only show your final response to the **User Query**! Do not provide any explanations or details."
66
+ },
67
+ {
68
+ "role": "user",
69
+ "content": prompt,
70
+ }
71
+ ]
72
+
73
+ client = Groq(api_key= os.environ["GROQ_API_KEY1"])
74
+ chat_completion = client.chat.completions.create(
75
+ messages=messages,
76
+ model="llama3-70b-8192",
77
+ )
78
+
79
+ response = chat_completion.choices[0].message.content
80
+ print(response)
81
+
82
+ text_file = open("Output.txt", "w")
83
+
84
+ text_file.write(response)
85
+
86
+ text_file.close()
87
+
88
+ return "Output.txt"
89
+
90
+
91
+
92
+ with gr.Blocks() as demo:
93
+
94
+ with gr.Tab("Excel to Neo4J"):
95
+ gr.Markdown("### Transfer your excel data in a Neo4J database using this tool !")
96
+
97
+ ex_fi = gr.File(file_count='single')
98
+ csv_fi = gr.File(file_count='single')
99
+
100
+ columns = gr.Dropdown(label="Columns of the file", multiselect=True, allow_custom_value=True)
101
+
102
+ remarks = gr.Dropdown(["This file do not contain information about Topic or Expert Nodes", "This file do not contain information about Document Nodes", "This file do not contain information about Solution Nodes", "This file do not contain information about Problem nodes"], label="Remarks", multiselect=True, allow_custom_value=True)
103
+
104
+ btn_submit = gr.Button("Submit")
105
+
106
+ result_fi = gr.File(file_count='single')
107
+
108
+ ex_fi.upload(excel_to_csv, inputs=ex_fi, outputs=[ex_fi, csv_fi])
109
+
110
+ btn_submit.click(text_to_neo4j, inputs=[remarks, columns], outputs=result_fi)
111
+
112
+
113
  demo.launch()