Rajan Singh commited on
Commit ·
f09166e
1
Parent(s): d8ea436
Done
Browse files- src/streamlit_app.py +14 -24
src/streamlit_app.py
CHANGED
|
@@ -1,31 +1,21 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
|
| 5 |
st.title("Uzmi GPT - Romantic Quote Generator")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
if st.button("Generate"):
|
| 12 |
-
API_URL = "https://api-inference.huggingface.co/models/rajan3208/uzmi-gpt"
|
| 13 |
-
headers = {
|
| 14 |
-
"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
payload = {"inputs": user_input}
|
| 18 |
|
| 19 |
-
|
| 20 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
except Exception as e:
|
| 28 |
-
st.error("Could not parse response.")
|
| 29 |
-
st.json(response.json())
|
| 30 |
-
else:
|
| 31 |
-
st.error(f"Error {response.status_code}: {response.text}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
st.title("Uzmi GPT - Romantic Quote Generator")
|
| 6 |
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_model():
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained("rajan3208/uzmi-gpt")
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained("rajan3208/uzmi-gpt")
|
| 11 |
+
return tokenizer, model
|
| 12 |
|
| 13 |
+
tokenizer, model = load_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
prompt = st.text_area("Enter a prompt", "A romantic quote about forever")
|
|
|
|
| 16 |
|
| 17 |
+
if st.button("Generate"):
|
| 18 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 19 |
+
output = model.generate(**inputs, max_new_tokens=50)
|
| 20 |
+
generated = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 21 |
+
st.success(generated)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|