Tarive commited on
Commit
2e7af1a
·
verified ·
1 Parent(s): 059a058

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -3,23 +3,34 @@ import os
3
  import gradio as gr
4
  import keras
5
  import keras_hub
6
- from huggingface_hub import from_pretrained_keras
 
7
 
8
  # Set Keras backend
9
  os.environ["KERAS_BACKEND"] = "jax"
10
  os.environ["XLA_PYTHON_CLIENT_MEM_FRACTION"] = "1.00"
11
 
12
- # --- 1. LOAD THE MERGED MODEL FROM THE HUB ---
13
- # Make sure this repo_id is correct and does not have any hidden characters at the end
 
14
  repo_id = "Tarive/lora_research_abstracts"
15
- print(f"Loading merged model from Hub: {repo_id}")
16
- gemma_lm = from_pretrained_keras(repo_id)
 
 
 
 
 
 
 
 
17
 
18
  # Compile the model with a sampler for generation
19
  gemma_lm.compile(sampler=keras_hub.samplers.TopKSampler(k=5))
20
  print("Model loaded and compiled successfully.")
21
 
22
- # --- 2. DEFINE THE INFERENCE FUNCTION ---
 
23
  def revise_abstract(draft_abstract, grant_type):
24
  if not draft_abstract or not grant_type:
25
  return "Error: Please provide both a draft abstract and a grant type."
@@ -38,7 +49,7 @@ def revise_abstract(draft_abstract, grant_type):
38
  parts = output.split("Revised Abstract:")
39
  return parts[1].strip() if len(parts) > 1 else output.strip()
40
 
41
- # --- 3. CREATE THE GRADIO INTERFACE ---
42
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
43
  gr.Markdown("# Grant Abstract Revision Tool (Fine-Tuned on Gemma)")
44
  gr.Markdown("Enter a draft abstract and select its grant type. The model will rewrite it to be more impactful, based on patterns from successfully funded NIH grants.")
 
3
  import gradio as gr
4
  import keras
5
  import keras_hub
6
+ # Import the specific downloader function
7
+ from huggingface_hub import hf_hub_download
8
 
9
  # Set Keras backend
10
  os.environ["KERAS_BACKEND"] = "jax"
11
  os.environ["XLA_PYTHON_CLIENT_MEM_FRACTION"] = "1.00"
12
 
13
+ # --- 1. LOAD THE MERGED MODEL FROM THE HUB (CORRECTED METHOD) ---
14
+
15
+ # Define your repository and the filename of the model
16
  repo_id = "Tarive/lora_research_abstracts"
17
+ model_filename = "model.keras" # The name we used during the upload step
18
+
19
+ print(f"Downloading model file '{model_filename}' from Hub repo: {repo_id}")
20
+ # Step 1: Explicitly download the .keras file and get its local path in the cache
21
+ model_path = hf_hub_download(repo_id=repo_id, filename=model_filename)
22
+
23
+ print(f"Loading merged model from local path: {model_path}")
24
+ # Step 2: Load the model directly from the specific file path
25
+ # This avoids the directory format error.
26
+ gemma_lm = keras.models.load_model(model_path)
27
 
28
  # Compile the model with a sampler for generation
29
  gemma_lm.compile(sampler=keras_hub.samplers.TopKSampler(k=5))
30
  print("Model loaded and compiled successfully.")
31
 
32
+
33
+ # --- 2. DEFINE THE INFERENCE FUNCTION (No changes needed here) ---
34
  def revise_abstract(draft_abstract, grant_type):
35
  if not draft_abstract or not grant_type:
36
  return "Error: Please provide both a draft abstract and a grant type."
 
49
  parts = output.split("Revised Abstract:")
50
  return parts[1].strip() if len(parts) > 1 else output.strip()
51
 
52
+ # --- 3. CREATE THE GRADIO INTERFACE (No changes needed here) ---
53
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
54
  gr.Markdown("# Grant Abstract Revision Tool (Fine-Tuned on Gemma)")
55
  gr.Markdown("Enter a draft abstract and select its grant type. The model will rewrite it to be more impactful, based on patterns from successfully funded NIH grants.")