Added some images for looks
Browse files
app.py
CHANGED
|
@@ -44,7 +44,7 @@ import torch
|
|
| 44 |
# So first run will load and save resources to global cache, and as user interact and causes rerun of load_model_and_tokenizer(), instead of loading again it will directly use cached resources from memory
|
| 45 |
def load_model_and_tokenizer():
|
| 46 |
model_name = "google/gemma-2b" # using gemma-2b for prototype for my GSOC Proposal. Wish me luck.
|
| 47 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 48 |
# Responsible for automatically downloading and loading the tokenizer configuration and vocabulary associated with the specified pre-trained model.
|
| 49 |
# Downloads and loads the tokenizer config and vocab for the given model
|
| 50 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
@@ -64,7 +64,7 @@ def generate_text(prompt, tone, max_length, temperature=0.7, top_p=0.9, repetiti
|
|
| 64 |
}
|
| 65 |
input_text = tone_prompts.get(tone, prompt)
|
| 66 |
|
| 67 |
-
inputs = tokenizer(input_text, return_tensors="pt")
|
| 68 |
outputs = model.generate(
|
| 69 |
inputs["input_ids"],
|
| 70 |
max_length=max_length + len(input_text.split()),
|
|
@@ -76,19 +76,78 @@ def generate_text(prompt, tone, max_length, temperature=0.7, top_p=0.9, repetiti
|
|
| 76 |
)
|
| 77 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 78 |
|
| 79 |
-
#
|
| 80 |
st.markdown("""
|
| 81 |
<style>
|
| 82 |
-
|
| 83 |
-
.
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
</style>
|
| 87 |
""", unsafe_allow_html=True)
|
| 88 |
|
| 89 |
-
#
|
| 90 |
-
st.
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# Instructions and example
|
| 94 |
st.markdown("""
|
|
@@ -176,5 +235,9 @@ if submit_button or st.session_state.trigger_example:
|
|
| 176 |
|
| 177 |
# Footer
|
| 178 |
st.markdown("---")
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
# So first run will load and save resources to global cache, and as user interact and causes rerun of load_model_and_tokenizer(), instead of loading again it will directly use cached resources from memory
|
| 45 |
def load_model_and_tokenizer():
|
| 46 |
model_name = "google/gemma-2b" # using gemma-2b for prototype for my GSOC Proposal. Wish me luck.
|
| 47 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 48 |
# Responsible for automatically downloading and loading the tokenizer configuration and vocabulary associated with the specified pre-trained model.
|
| 49 |
# Downloads and loads the tokenizer config and vocab for the given model
|
| 50 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
|
|
| 64 |
}
|
| 65 |
input_text = tone_prompts.get(tone, prompt)
|
| 66 |
|
| 67 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 68 |
outputs = model.generate(
|
| 69 |
inputs["input_ids"],
|
| 70 |
max_length=max_length + len(input_text.split()),
|
|
|
|
| 76 |
)
|
| 77 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 78 |
|
| 79 |
+
# Updated CSS for a modern, awesome look
|
| 80 |
st.markdown("""
|
| 81 |
<style>
|
| 82 |
+
/* Background image with fallback */
|
| 83 |
+
.stApp {
|
| 84 |
+
background: linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0.6)), url('images/background.png');
|
| 85 |
+
background-size: cover;
|
| 86 |
+
background-position: center;
|
| 87 |
+
color: #ffffff; /* White text for contrast */
|
| 88 |
+
}
|
| 89 |
+
/* Cool gradient title with hover animation */
|
| 90 |
+
.title {
|
| 91 |
+
background: linear-gradient(90deg, #00d2ff, #3a7bd5);
|
| 92 |
+
-webkit-background-clip: text;
|
| 93 |
+
color: transparent;
|
| 94 |
+
font-size: 40px;
|
| 95 |
+
font-weight: bold;
|
| 96 |
+
transition: transform 0.3s;
|
| 97 |
+
}
|
| 98 |
+
.title:hover {
|
| 99 |
+
transform: scale(1.05);
|
| 100 |
+
}
|
| 101 |
+
/* Card-like instructions */
|
| 102 |
+
.instructions {
|
| 103 |
+
background: rgba(255, 255, 255, 0.1);
|
| 104 |
+
padding: 15px;
|
| 105 |
+
border-radius: 10px;
|
| 106 |
+
box-shadow: 0 5px 20px rgba(0,0,0,0.3);
|
| 107 |
+
font-size: 18px;
|
| 108 |
+
color: #e0e0e0;
|
| 109 |
+
}
|
| 110 |
+
/* Neon glow output box */
|
| 111 |
+
.output-box {
|
| 112 |
+
background: rgba(30, 30, 50, 0.9);
|
| 113 |
+
padding: 15px;
|
| 114 |
+
border-radius: 12px;
|
| 115 |
+
box-shadow: 0 0 15px #00d2ff, 0 0 30px #3a7bd5;
|
| 116 |
+
font-family: 'Courier New', monospace;
|
| 117 |
+
font-size: 16px;
|
| 118 |
+
color: #ffffff;
|
| 119 |
+
white-space: pre-wrap;
|
| 120 |
+
animation: glow 1.5s infinite alternate;
|
| 121 |
+
}
|
| 122 |
+
@keyframes glow {
|
| 123 |
+
from { box-shadow: 0 0 10px #00d2ff; }
|
| 124 |
+
to { box-shadow: 0 0 20px #3a7bd5; }
|
| 125 |
+
}
|
| 126 |
+
/* Button hover effect */
|
| 127 |
+
.stButton>button {
|
| 128 |
+
background: #3a7bd5;
|
| 129 |
+
color: white;
|
| 130 |
+
border-radius: 8px;
|
| 131 |
+
transition: all 0.3s;
|
| 132 |
+
}
|
| 133 |
+
.stButton>button:hover {
|
| 134 |
+
background: #00d2ff;
|
| 135 |
+
transform: translateY(-2px);
|
| 136 |
+
}
|
| 137 |
+
/* Slider styling */
|
| 138 |
+
.stSlider>div>div>div {
|
| 139 |
+
background: #00d2ff !important;
|
| 140 |
+
}
|
| 141 |
</style>
|
| 142 |
""", unsafe_allow_html=True)
|
| 143 |
|
| 144 |
+
# Header with GSoC logo
|
| 145 |
+
col1, col2 = st.columns([3, 1])
|
| 146 |
+
with col1:
|
| 147 |
+
st.markdown('<p class="title">Gemma Text Generator</p>', unsafe_allow_html=True)
|
| 148 |
+
with col2:
|
| 149 |
+
st.image("images/gsoc_logo.png", width=80, caption="GSoC 2025")
|
| 150 |
+
|
| 151 |
|
| 152 |
# Instructions and example
|
| 153 |
st.markdown("""
|
|
|
|
| 235 |
|
| 236 |
# Footer
|
| 237 |
st.markdown("---")
|
| 238 |
+
col1, col2 = st.columns([3, 1])
|
| 239 |
+
with col1:
|
| 240 |
+
st.write("Built with ❤️ by Utkarsh Shukla for GSoC Proposal 2025 | Powered by (Gemma + Hugging Face) and Saiyan Pride")
|
| 241 |
+
st.write("Wish me luck, 🤞")
|
| 242 |
+
with col2:
|
| 243 |
+
st.image("images/gemma_logo.png", width=80, caption="Gemma by DeepMind")
|