Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,7 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load tokenizer and model
|
| 6 |
model_id = "microsoft/Magma-8B"
|
| 7 |
-
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 9 |
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
model_id,
|
|
@@ -12,14 +10,12 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 12 |
trust_remote_code=True
|
| 13 |
)
|
| 14 |
|
| 15 |
-
# Define a simple text-generation function
|
| 16 |
def generate_response(prompt):
|
| 17 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 18 |
with torch.no_grad():
|
| 19 |
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 20 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 21 |
|
| 22 |
-
# Create Gradio interface
|
| 23 |
interface = gr.Interface(
|
| 24 |
fn=generate_response,
|
| 25 |
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
|
@@ -27,5 +23,4 @@ interface = gr.Interface(
|
|
| 27 |
title="Magma-8B Text Generator"
|
| 28 |
)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
interface.launch()
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
|
|
|
| 5 |
model_id = "microsoft/Magma-8B"
|
|
|
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 7 |
model = AutoModelForCausalLM.from_pretrained(
|
| 8 |
model_id,
|
|
|
|
| 10 |
trust_remote_code=True
|
| 11 |
)
|
| 12 |
|
|
|
|
| 13 |
def generate_response(prompt):
|
| 14 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 15 |
with torch.no_grad():
|
| 16 |
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 17 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
|
|
|
|
| 19 |
interface = gr.Interface(
|
| 20 |
fn=generate_response,
|
| 21 |
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
|
|
|
| 23 |
title="Magma-8B Text Generator"
|
| 24 |
)
|
| 25 |
|
| 26 |
+
interface.launch(share=False, enable_queue=True)
|
|
|