RichieBurundi commited on
Commit
eef425a
1 Parent(s): 4948e07

Create burundi.py

Browse files
Files changed (1) hide show
  1. burundi.py +40 -0
burundi.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import sqlite3
4
+
5
+ model_name = "your-model-name"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ def read_files_from_db():
10
+ conn = sqlite3.connect('your_database.db')
11
+ cursor = conn.cursor()
12
+ cursor.execute("SELECT * FROM files")
13
+ files = cursor.fetchall()
14
+ conn.close()
15
+ return files
16
+
17
+ def generate_code(input_text):
18
+ files = read_files_from_db()
19
+
20
+ context = "Available files:\n"
21
+ for file in files:
22
+ context += f"- {file[1]}\n"
23
+
24
+ prompt = f"{context}\nGenerate code based on the following input:\n{input_text}\n"
25
+
26
+ inputs = tokenizer(prompt, return_tensors="pt")
27
+ outputs = model.generate(**inputs, max_length=500)
28
+ generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
29
+
30
+ return generated_code
31
+
32
+ iface = gr.Interface(
33
+ fn=generate_code,
34
+ inputs="text",
35
+ outputs="text",
36
+ title="Code Generation AI",
37
+ description="Enter your code or instructions, and the AI will generate code based on available files."
38
+ )
39
+
40
+ iface.launch()