Spaces:
Sleeping
Sleeping
Create App.py
Browse files
App.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import cached_download, hf_hub_url
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Model ID from Hugging Face Hub
|
5 |
+
MODEL_ID = "ISTA-DASLab/gemma-2b-AQLM-2Bit-2x8-hf"
|
6 |
+
|
7 |
+
# Download the model (if not already cached)
|
8 |
+
model = cached_download(hf_hub_url(MODEL_ID))
|
9 |
+
|
10 |
+
# Create a text generation pipeline
|
11 |
+
generator = pipeline("text-generation", model=model)
|
12 |
+
|
13 |
+
def generate_text(prompt):
|
14 |
+
"""Generates text using the loaded model.
|
15 |
+
|
16 |
+
Args:
|
17 |
+
prompt: The user input to guide the generation.
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
The generated text.
|
21 |
+
"""
|
22 |
+
generated_text = generator(prompt, max_length=50, num_return_sequences=1)[0]['generated_text']
|
23 |
+
return generated_text
|
24 |
+
|
25 |
+
# Space UI (using Streamlit for demonstration)
|
26 |
+
import streamlit as st
|
27 |
+
|
28 |
+
st.title("Text Generation with ISTA-DASLab/gemma-2b-AQLM-2Bit-2x8-hf")
|
29 |
+
prompt = st.text_input("Enter a prompt (e.g., My name is Teven and I am...)")
|
30 |
+
|
31 |
+
if st.button("Generate"):
|
32 |
+
generated_text = generate_text(prompt)
|
33 |
+
st.write(generated_text)
|