Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,25 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
+
# Load the GPT-NeoX model and tokenizer
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b")
|
7 |
+
|
8 |
+
# Define system instructions
|
9 |
+
SYSTEM_INSTRUCTIONS = (
|
10 |
+
"You are a helpful assistant specializing in gaming system instructions. "
|
11 |
+
"Follow all commands precisely. Provide step-by-step details for each task."
|
12 |
+
)
|
13 |
+
|
14 |
+
# Define the function for querying the model
|
15 |
+
def generate_response(user_input):
|
16 |
+
# Prepend the system instructions to the user's input
|
17 |
+
prompt = SYSTEM_INSTRUCTIONS + "\nUser: " + user_input + "\nAssistant:"
|
18 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
19 |
+
outputs = model.generate(**inputs, max_length=300, do_sample=True)
|
20 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
21 |
+
return response.split("Assistant:")[-1].strip()
|
22 |
+
|
23 |
+
# Create a Gradio interface
|
24 |
+
interface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
|
25 |
+
interface.launch()
|