Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ print(f"Using device: {device}")
|
|
| 8 |
|
| 9 |
# Load the fine-tuned Phi-2 model in 4-bit quantization with CPU support
|
| 10 |
#model_name = "./fine-tuned-phi2"
|
| 11 |
-
model_name = "microsoft/phi-2
|
| 12 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float32, device_map={"": device})
|
| 13 |
|
| 14 |
# Load tokenizer
|
|
@@ -23,25 +23,21 @@ def generate_response(prompt):
|
|
| 23 |
|
| 24 |
# Define example prompts
|
| 25 |
examples = [
|
| 26 |
-
["What is
|
| 27 |
["Explain quantum mechanics in simple terms."],
|
| 28 |
["Write a short story about a robot discovering emotions."],
|
| 29 |
["Summarize the theory of relativity."]
|
| 30 |
]
|
| 31 |
|
| 32 |
# Create Gradio UI
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
gr.
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
btn.click(fn=generate_response, inputs=txt, outputs=output)
|
| 43 |
-
|
| 44 |
-
gr.Examples(examples=[[ex] for ex in examples], inputs=txt)
|
| 45 |
|
| 46 |
# Launch Gradio app
|
| 47 |
-
|
|
|
|
| 8 |
|
| 9 |
# Load the fine-tuned Phi-2 model in 4-bit quantization with CPU support
|
| 10 |
#model_name = "./fine-tuned-phi2"
|
| 11 |
+
model_name = "microsoft/phi-2
|
| 12 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float32, device_map={"": device})
|
| 13 |
|
| 14 |
# Load tokenizer
|
|
|
|
| 23 |
|
| 24 |
# Define example prompts
|
| 25 |
examples = [
|
| 26 |
+
["What is the capital of France?"],
|
| 27 |
["Explain quantum mechanics in simple terms."],
|
| 28 |
["Write a short story about a robot discovering emotions."],
|
| 29 |
["Summarize the theory of relativity."]
|
| 30 |
]
|
| 31 |
|
| 32 |
# Create Gradio UI
|
| 33 |
+
iface = gr.Interface(
|
| 34 |
+
fn=generate_response,
|
| 35 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 36 |
+
outputs=gr.Textbox(),
|
| 37 |
+
title="Phi-2 LoRA Model",
|
| 38 |
+
description="A fine-tuned Phi-2 model with LoRA running on Hugging Face Spaces (CPU optimized).",
|
| 39 |
+
examples=examples,
|
| 40 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Launch Gradio app
|
| 43 |
+
iface.launch()
|