DemahAlmutairi commited on
Commit
9ad974d
·
verified ·
1 Parent(s): e05d77b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -1,12 +1,12 @@
1
  import os
2
  import gradio as gr
3
  from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
4
- import torch
5
  import spaces
6
 
7
  # Create the necessary directories
8
  os.makedirs('.gradio/cached_examples/17', exist_ok=True)
9
 
 
10
  def get_model_name(language):
11
  """Map language choice to the corresponding model."""
12
  model_mapping = {
@@ -53,6 +53,17 @@ def generate_kids_story(character, setting, language):
53
  output = generator(messages)
54
  return output[0]["generated_text"]
55
 
 
 
 
 
 
 
 
 
 
 
 
56
  # Create Gradio interface
57
  demo = gr.Interface(
58
  fn=generate_kids_story,
@@ -78,4 +89,4 @@ demo = gr.Interface(
78
  )
79
 
80
  # Launch the Gradio app
81
- demo.launch(cache_examples = False)
 
1
  import os
2
  import gradio as gr
3
  from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
 
4
  import spaces
5
 
6
  # Create the necessary directories
7
  os.makedirs('.gradio/cached_examples/17', exist_ok=True)
8
 
9
+
10
  def get_model_name(language):
11
  """Map language choice to the corresponding model."""
12
  model_mapping = {
 
53
  output = generator(messages)
54
  return output[0]["generated_text"]
55
 
56
+ import gc
57
+ import torch
58
+ # Delete model and associated objects
59
+ del model
60
+ del tokenizer
61
+ del generator
62
+ # Run garbage collection
63
+ gc.collect ()
64
+ # Empty CUDA cache
65
+ torch.cuda.empty_cache()
66
+
67
  # Create Gradio interface
68
  demo = gr.Interface(
69
  fn=generate_kids_story,
 
89
  )
90
 
91
  # Launch the Gradio app
92
+ demo.launch()