Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,24 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# gr.load("models/infly/OpenCoder-8B-Instruct").launch()
|
| 8 |
-
# @spaces.GPU
|
| 9 |
-
#else:
|
| 10 |
-
# raise RuntimeError("No compatible GPU environment found for this model.")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
+
# Load model and tokenizer
|
| 5 |
+
model_name = "infly/OpenCoder-8B-Instruct"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
@spaces.GPU
|
| 10 |
+
def generate_text(prompt):
|
| 11 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True)
|
| 12 |
+
outputs = model.generate(inputs["input_ids"], max_length=100, num_return_sequences=1)
|
| 13 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
|
| 15 |
+
# Create Gradio interface
|
| 16 |
+
interface = gr.Interface(
|
| 17 |
+
fn=generate_text,
|
| 18 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 19 |
+
outputs=gr.Textbox(label="Generated Text")
|
| 20 |
+
)
|
| 21 |
|
| 22 |
+
# Launch the Gradio app
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
interface.launch()
|