frankai98 commited on
Commit
e8b9998
·
verified ·
1 Parent(s): 65fef18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -18
app.py CHANGED
@@ -2,7 +2,7 @@ import nest_asyncio
2
  nest_asyncio.apply()
3
 
4
  import streamlit as st
5
- from transformers import pipeline, BitsAndBytesConfig
6
  import torch
7
  from gtts import gTTS
8
  import io
@@ -62,24 +62,9 @@ st.header("Turn Your Image to a Short Audio Story for Children")
62
  # Model loading
63
  @st.cache_resource
64
  def load_models():
65
- # Configure 4-bit quantization properly
66
- quantization_config = BitsAndBytesConfig(
67
- load_in_4bit=True,
68
- bnb_4bit_compute_dtype=torch.float16,
69
- bnb_4bit_quant_type="nf4"
70
- )
71
-
72
  return {
73
  "img_model": pipeline("image-to-text", "cnmoro/tiny-image-captioning"),
74
- "story_model": pipeline(
75
- "text-generation",
76
- "Qwen/Qwen2.5-0.5B-Instruct",
77
- device_map="auto",
78
- model_kwargs={
79
- "quantization_config": quantization_config,
80
- "torch_dtype": torch.float16
81
- }
82
- )
83
  }
84
 
85
  models = load_models()
@@ -96,7 +81,7 @@ def text2story(text):
96
  ]
97
  response = models["story_model"](
98
  messages,
99
- max_new_tokens=128,
100
  do_sample=True,
101
  temperature=0.7
102
  )[0]["generated_text"]
 
2
  nest_asyncio.apply()
3
 
4
  import streamlit as st
5
+ from transformers import pipeline
6
  import torch
7
  from gtts import gTTS
8
  import io
 
62
  # Model loading
63
  @st.cache_resource
64
  def load_models():
 
 
 
 
 
 
 
65
  return {
66
  "img_model": pipeline("image-to-text", "cnmoro/tiny-image-captioning"),
67
+ "story_model": pipeline("text-generation", "Qwen/Qwen2.5-0.5B-Instruct")
 
 
 
 
 
 
 
 
68
  }
69
 
70
  models = load_models()
 
81
  ]
82
  response = models["story_model"](
83
  messages,
84
+ max_new_tokens=100,
85
  do_sample=True,
86
  temperature=0.7
87
  )[0]["generated_text"]