Spaces:
Sleeping
Sleeping
File size: 1,079 Bytes
8b8242c 32414d2 fc92fad bde561e fc92fad bde561e 8b8242c fc92fad 8b8242c fc92fad bde561e fc92fad 8b8242c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import streamlit as st
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import os
# Load Hugging Face Token from environment variable
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
if hf_token is None:
st.error("❌ Hugging Face API Token is missing! Add it in Settings → Secrets.")
st.stop()
# Model name
MODEL_NAME = "google/gemma-2b-it"
# Load tokenizer and model with authentication
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_auth_token=hf_token)
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, device_map="auto", use_auth_token=hf_token)
# Streamlit UI
st.title("Gemma-2B Code Assistant")
user_input = st.text_area("Enter your coding query:")
if st.button("Generate Code"):
if user_input:
inputs = tokenizer(user_input, return_tensors="pt").to("cuda")
output = model.generate(**inputs, max_new_tokens=100)
response = tokenizer.decode(output[0], skip_special_tokens=True)
st.write(response)
else:
st.warning("Please enter a query!")
|