Spaces:
Sleeping
Sleeping
Keira James
commited on
Commit
·
d19bd0a
1
Parent(s):
002b1b3
Update app file
Browse files
app.py
CHANGED
|
@@ -1,5 +1,24 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import torch
|
| 3 |
|
| 4 |
+
# Function to generate a response
|
| 5 |
+
def generate_response(prompt):
|
| 6 |
+
if not prompt:
|
| 7 |
+
return "Please enter a prompt."
|
| 8 |
+
|
| 9 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 10 |
+
output = model.generate(**inputs, max_new_tokens=512)
|
| 11 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 12 |
+
|
| 13 |
+
return response
|
| 14 |
+
|
| 15 |
+
# Streamlit UI
|
| 16 |
+
st.title("AI Text Generator")
|
| 17 |
+
|
| 18 |
+
prompt = st.text_area("Enter your prompt:", placeholder="Type your question or prompt here...")
|
| 19 |
+
|
| 20 |
+
if st.button("Generate Response"):
|
| 21 |
+
with st.spinner("Generating response..."):
|
| 22 |
+
response = generate_response(prompt)
|
| 23 |
+
st.text_area("Model Response:", value=response, height=200, disabled=True)
|
| 24 |
|