Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/todolistapp/DatabaseUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package todolistapp;

/**
*
* @author Sajeev
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DatabaseUtil{
private static final String DB_URL = "jdbc:sqlite:C:\\Users\\Sajeev\\Downloads\\mydatabase\\vector_search.db";

public static Connection connect() {
Connection conn = null;
try {
conn = DriverManager.getConnection(DB_URL);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return conn;
}
}

64 changes: 64 additions & 0 deletions src/todolistapp/HuggingFaceClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package todolistapp;

/**
*
* @author Sajeev
*/
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

public class HuggingFaceClient {

private static final String API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/all-MiniLM-L6-v2";
private static final String API_KEY = "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";


public static String generateEmbedding(String sourceSentence, String[] sentences) {
try {
URL url = new URL(API_URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Bearer " + API_KEY);
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);

// Prepare JSON payload
StringBuilder sentencesArrayJson = new StringBuilder("[");
for (int i = 0; i < sentences.length; i++) {
sentencesArrayJson.append("\"").append(sentences[i]).append("\"");
if (i < sentences.length - 1) {
sentencesArrayJson.append(",");
}
}
sentencesArrayJson.append("]");

String payload = String.format("{\"inputs\": {\"source_sentence\": \"%s\", \"sentences\": %s}}",
sourceSentence, sentencesArrayJson.toString());

// Write payload
try (OutputStream os = conn.getOutputStream()) {
os.write(payload.getBytes());
os.flush();
}

// Read response
Scanner scanner = new Scanner(conn.getInputStream());
StringBuilder response = new StringBuilder();
while (scanner.hasNextLine()) {
response.append(scanner.nextLine());
}
scanner.close();

return response.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
110 changes: 110 additions & 0 deletions src/todolistapp/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package todolistapp;

/**
*
* @author Sajeev
*/
import java.time.LocalDate;

public class Task {
private String title;
private String description;
private LocalDate dueDate;
private boolean isComplete;
private String category;
private String priority;
private Task dependsOn;
private boolean isRecurring;
private String recurringInterval;

// Constructor
public Task(String title, String description, LocalDate dueDate, String category, String priority, boolean isRecurring, String recurringInterval) {
this.title = title;
this.description = description;
this.dueDate = dueDate;
this.isComplete = false;
this.category = category;
this.priority = priority;
this.dependsOn = null;
this.isRecurring = isRecurring;
this.recurringInterval = recurringInterval;
}

// Getters
public String getTitle() {
return title;
}

public String getDescription() {
return description;
}

public LocalDate getDueDate() {
return dueDate;
}

public boolean isComplete() {
return isComplete;
}

public String getCategory() {
return category;
}

public String getPriority() {
return priority;
}

public Task getDependsOn() {
return dependsOn;
}

public boolean isRecurring() {
return isRecurring;
}

public String getRecurringInterval() {
return recurringInterval;
}

// Setters
public void setTitle(String title) {
this.title = title;
}

public void setDescription(String description) {
this.description = description;
}

public void setDueDate(LocalDate dueDate) {
this.dueDate = dueDate;
}

public void setComplete(boolean complete) {
isComplete = complete;
}

public void setCategory(String category) {
this.category = category;
}

public void setPriority(String priority) {
this.priority = priority;
}

public void setDependsOn(Task dependsOn) {
this.dependsOn = dependsOn;
}

public void setRecurring(boolean recurring) {
isRecurring = recurring;
}

public void setRecurringInterval(String recurringInterval) {
this.recurringInterval = recurringInterval;
}
}
44 changes: 44 additions & 0 deletions src/todolistapp/TaskDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package todolistapp;



/**
*
* @author Sajeev
*/

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class TaskDAO {

public void insertTask(String title, String description, String dueDate, String category, String priority, String completionStatus) {
String sql = "INSERT INTO vector_tasks (title, description, due_date, category, priority, completion_status) VALUES (?, ?, ?, ?, ?, ?)";

try (Connection conn = DatabaseUtil.connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {

pstmt.setString(1, title);
pstmt.setString(2, description);
pstmt.setString(3, dueDate);
pstmt.setString(4, category);
pstmt.setString(5, priority);
pstmt.setString(6, completionStatus);

pstmt.executeUpdate();
System.out.println("Task added successfully to the database!");

} catch (SQLException e) {
System.out.println("Error adding task to database: " + e.getMessage());
}
}
}




Loading