Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,27 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
|
5 |
+
# Load the Unsloth Phi-4 GGUF model and tokenizer
|
6 |
+
model_name = "unsloth/phi-4-gguf"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
9 |
+
|
10 |
+
# Function to generate code based on user input
|
11 |
+
def generate_code(prompt):
|
12 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
13 |
+
outputs = model.generate(**inputs, max_length=150)
|
14 |
+
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
15 |
+
return generated_code
|
16 |
+
|
17 |
+
# Gradio interface
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=generate_code,
|
20 |
+
inputs=gr.Textbox(lines=5, label="Prompt"),
|
21 |
+
outputs=gr.Code(language="python", label="Generated Code"),
|
22 |
+
title="Code Generator with Unsloth Phi-4 GGUF",
|
23 |
+
description="Enter a prompt to generate Python code using the Unsloth Phi-4 GGUF model."
|
24 |
+
)
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
interface.launch()
|