Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,10 +10,6 @@ def load_model(model_name):
|
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 11 |
return tokenizer, model
|
| 12 |
|
| 13 |
-
# Models to compare
|
| 14 |
-
original_model_name = "Vishwas1/hummingbird-base-marathi-finetuned"
|
| 15 |
-
fine_tuned_model_name = "Vishwas1/hummingbird-base-marathi-finetuned-finetuned"
|
| 16 |
-
|
| 17 |
# Load Hugging Face token
|
| 18 |
hf_token = os.getenv('HF_API_TOKEN')
|
| 19 |
if not hf_token:
|
|
@@ -22,16 +18,16 @@ if not hf_token:
|
|
| 22 |
# Login to Hugging Face Hub
|
| 23 |
login(hf_token)
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
# Ensure models are in evaluation mode
|
| 30 |
-
original_model.eval()
|
| 31 |
-
fine_tuned_model.eval()
|
| 32 |
|
| 33 |
-
# Function to compare text generation from both models
|
| 34 |
-
def compare_models(prompt):
|
| 35 |
# Generate text with the original model
|
| 36 |
inputs_orig = original_tokenizer(prompt, return_tensors="pt")
|
| 37 |
with torch.no_grad():
|
|
@@ -54,13 +50,15 @@ def compare_models(prompt):
|
|
| 54 |
# Gradio Interface
|
| 55 |
iface = gr.Interface(
|
| 56 |
fn=compare_models,
|
| 57 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
outputs=gr.JSON(label="Generated Texts"),
|
| 59 |
title="Compare Text Generation from Original and Fine-Tuned Models",
|
| 60 |
-
description="Enter a prompt to generate text from the original and fine-tuned models."
|
| 61 |
)
|
| 62 |
|
| 63 |
iface.launch()
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 11 |
return tokenizer, model
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Load Hugging Face token
|
| 14 |
hf_token = os.getenv('HF_API_TOKEN')
|
| 15 |
if not hf_token:
|
|
|
|
| 18 |
# Login to Hugging Face Hub
|
| 19 |
login(hf_token)
|
| 20 |
|
| 21 |
+
# Function to compare text generation from both models
|
| 22 |
+
def compare_models(prompt, original_model_name, fine_tuned_model_name):
|
| 23 |
+
# Load the original and fine-tuned models based on user input
|
| 24 |
+
original_tokenizer, original_model = load_model(original_model_name)
|
| 25 |
+
fine_tuned_tokenizer, fine_tuned_model = load_model(fine_tuned_model_name)
|
| 26 |
|
| 27 |
+
# Ensure models are in evaluation mode
|
| 28 |
+
original_model.eval()
|
| 29 |
+
fine_tuned_model.eval()
|
| 30 |
|
|
|
|
|
|
|
| 31 |
# Generate text with the original model
|
| 32 |
inputs_orig = original_tokenizer(prompt, return_tensors="pt")
|
| 33 |
with torch.no_grad():
|
|
|
|
| 50 |
# Gradio Interface
|
| 51 |
iface = gr.Interface(
|
| 52 |
fn=compare_models,
|
| 53 |
+
inputs=[
|
| 54 |
+
gr.Textbox(lines=5, placeholder="Enter text here...", label="Input Text"),
|
| 55 |
+
gr.Textbox(lines=1, placeholder="Enter original model name...", label="Original Model Name", default="Vishwas1/hummingbird-base-marathi-finetuned"),
|
| 56 |
+
gr.Textbox(lines=1, placeholder="Enter fine-tuned model name...", label="Fine-Tuned Model Name", default="Vishwas1/hummingbird-base-marathi-finetuned-finetuned")
|
| 57 |
+
],
|
| 58 |
outputs=gr.JSON(label="Generated Texts"),
|
| 59 |
title="Compare Text Generation from Original and Fine-Tuned Models",
|
| 60 |
+
description="Enter a prompt and model names to generate text from the original and fine-tuned models."
|
| 61 |
)
|
| 62 |
|
| 63 |
iface.launch()
|
| 64 |
|
|
|
|
|
|