Zakomako4567 commited on
Commit
721ae99
·
verified ·
1 Parent(s): b313461

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
+
4
+ class ZewAI3:
5
+ def __init__(self, model_name="microsoft/phi-2"):
6
+ # We use phi-2 as a base because it's tiny but "super good" at coding
7
+ print(f"Initializing ZewAI 3 based on {model_name}...")
8
+ self.tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
9
+ self.model = AutoModelForCausalLM.from_pretrained(
10
+ model_name,
11
+ torch_dtype=torch.float32,
12
+ trust_remote_code=True
13
+ )
14
+ self.pipe = pipeline("text-generation", model=self.model, tokenizer=self.tokenizer)
15
+
16
+ def generate_code(self, prompt, max_length=512):
17
+ # Specific formatting to help the AI focus on coding logic
18
+ formatted_prompt = f"Instruct: Write the following code: {prompt}\nOutput:"
19
+
20
+ results = self.pipe(
21
+ formatted_prompt,
22
+ max_new_tokens=max_length,
23
+ do_sample=True,
24
+ temperature=0.7
25
+ )
26
+ return results[0]['generated_text']
27
+
28
+ # Example usage for the editor:
29
+ if __name__ == "__main__":
30
+ zew_model = ZewAI3()
31
+ test_prompt = "Create a single-file HTML app with a dark mode toggle."
32
+ print(zew_model.generate_code(test_prompt))