Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
+
model_name = "khaled123/chess"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# Define the function to generate text
|
| 10 |
+
def generate_text(prompt):
|
| 11 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 12 |
+
outputs = model.generate(inputs["input_ids"], max_length=50)
|
| 13 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
return generated_text
|
| 15 |
+
|
| 16 |
+
# Create the Gradio interface
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=generate_text,
|
| 19 |
+
inputs="text",
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="Chess Model based on LLaMA 2",
|
| 22 |
+
description="Type a prompt and the model will generate text based on it."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Launch the interface
|
| 26 |
+
iface.launch()
|