Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
+
|
4 |
+
# Load the finetuned model and tokenizer from Hugging Face Model Hub
|
5 |
+
model_path = "sagar007/phi3.5_finetune"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, device_map="auto")
|
8 |
+
|
9 |
+
# Create a text-generation pipeline
|
10 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
def generate_text(prompt, max_length=100, temperature=0.7):
|
13 |
+
"""Generate text based on the input prompt."""
|
14 |
+
generated = generator(prompt, max_length=max_length, temperature=temperature, num_return_sequences=1)
|
15 |
+
return generated[0]['generated_text']
|
16 |
+
|
17 |
+
# Create the Gradio interface
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=generate_text,
|
20 |
+
inputs=[
|
21 |
+
gr.Textbox(lines=5, label="Enter your prompt"),
|
22 |
+
gr.Slider(minimum=50, maximum=500, value=100, step=10, label="Max Length"),
|
23 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
|
24 |
+
],
|
25 |
+
outputs=gr.Textbox(lines=10, label="Generated Text"),
|
26 |
+
title="Finetuned Phi-3.5 Text Generation",
|
27 |
+
description="Enter a prompt and generate text using the finetuned Phi-3.5 model.",
|
28 |
+
)
|
29 |
+
|
30 |
+
# Launch the app
|
31 |
+
iface.launch()
|