Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import spaces
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
|
| 5 |
# Load model and tokenizer
|
|
@@ -7,34 +6,25 @@ model_name = "infly/OpenCoder-8B-Instruct"
|
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
|
| 9 |
|
| 10 |
-
|
| 11 |
def generate_text(prompt):
|
| 12 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True)
|
| 13 |
-
outputs = model.generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
|
|
|
|
| 16 |
iface = gr.Interface(
|
| 17 |
fn=generate_text,
|
| 18 |
-
inputs=
|
| 19 |
-
gr.Textbox(label="Enter your prompt", placeholder="Start typing...", lines=5)
|
| 20 |
-
#gr.Slider(minimum=50, maximum=200, value=100, step=1, label="Max Length"),
|
| 21 |
-
#gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
|
| 22 |
-
],
|
| 23 |
outputs="text",
|
| 24 |
title="OpenCoder 8B Instruct",
|
| 25 |
-
description="Generate text using the OpenCoder model.
|
| 26 |
)
|
| 27 |
|
| 28 |
# Launch the Gradio app
|
| 29 |
-
iface.launch(
|
| 30 |
-
|
| 31 |
-
# Create Gradio interface
|
| 32 |
-
# interface = gr.Interface(
|
| 33 |
-
# fn=generate_text,
|
| 34 |
-
# inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 35 |
-
# outputs=gr.Textbox(label="Generated Text")
|
| 36 |
-
# )
|
| 37 |
-
|
| 38 |
-
# # Launch the Gradio app
|
| 39 |
-
# if __name__ == "__main__":
|
| 40 |
-
# interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
# Load model and tokenizer
|
|
|
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 7 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
|
| 8 |
|
| 9 |
+
# Define the text generation function
|
| 10 |
def generate_text(prompt):
|
| 11 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True)
|
| 12 |
+
outputs = model.generate(
|
| 13 |
+
inputs["input_ids"],
|
| 14 |
+
attention_mask=inputs["attention_mask"], # Add attention mask
|
| 15 |
+
max_length=50, # Reduce max_length to conserve memory
|
| 16 |
+
num_return_sequences=1
|
| 17 |
+
)
|
| 18 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 19 |
|
| 20 |
+
# Create the Gradio interface
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=generate_text,
|
| 23 |
+
inputs=gr.Textbox(label="Enter your prompt", placeholder="Start typing...", lines=5),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
outputs="text",
|
| 25 |
title="OpenCoder 8B Instruct",
|
| 26 |
+
description="Generate text using the OpenCoder model. Input a prompt to generate responses.",
|
| 27 |
)
|
| 28 |
|
| 29 |
# Launch the Gradio app
|
| 30 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|