Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,20 @@
|
|
| 1 |
-
import
|
| 2 |
import json
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
url = "https://run.cerebrium.ai/pygmalion-6b-webhook/predict"
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
with st.chat_message("user"):
|
| 18 |
-
st.markdown(prompt)
|
| 19 |
-
# Add user message to chat history
|
| 20 |
-
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 21 |
-
|
| 22 |
-
# Encode the new user input and add end of sentence token
|
| 23 |
-
inputs = tokenizer.encode(prompt + tokenizer.eos_token, return_tensors="pt")
|
| 24 |
-
|
| 25 |
-
# Generate a response
|
| 26 |
-
outputs = model.generate(inputs, max_length=50, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
|
| 27 |
-
|
| 28 |
-
# Decode the response
|
| 29 |
-
response = requests.request("POST", url, headers=headers, data=payload)
|
| 30 |
-
|
| 31 |
-
# Display the response in the chat
|
| 32 |
-
with st.chat_message("bot"):
|
| 33 |
-
st.markdown(response)
|
| 34 |
-
# Add bot message to chat history
|
| 35 |
-
st.session_state.messages.append({"role": "bot", "content": response})
|
| 36 |
|
| 37 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import json
|
| 3 |
+
import requests
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
| 5 |
|
| 6 |
+
model_name = 'Pyg'
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("TheBloke/Pygmalion-7B-SuperHOT-8K-GPTQ")
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained("TheBloke/Pygmalion-7B-SuperHOT-8K-GPTQ")
|
| 9 |
|
| 10 |
+
def generate_text(input_text):
|
| 11 |
+
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
| 12 |
+
outputs = model.generate(input_ids, max_length=150, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
|
| 13 |
+
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
return text
|
| 15 |
|
| 16 |
+
iface = gr.Interface(fn=generate_text,
|
| 17 |
+
inputs=gr.inputs.Textbox(lines=5, placeholder='Enter text here...'),
|
| 18 |
+
outputs=gr.outputs.Textbox())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
iface.launch()
|