File size: 938 Bytes
242ba54
b8211bd
 
242ba54
b8211bd
242ba54
980de81
b8211bd
 
 
 
 
 
 
 
 
 
 
 
 
980de81
b8211bd
242ba54
b8211bd
 
 
 
242ba54
980de81
b8211bd
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# Load tokenizer and model
model_id = "microsoft/Magma-8B"

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    trust_remote_code=True
)

# Define a simple text-generation function
def generate_response(prompt):
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
    with torch.no_grad():
        outputs = model.generate(**inputs, max_new_tokens=100)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

# Create Gradio interface
interface = gr.Interface(
    fn=generate_response,
    inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
    outputs="text",
    title="Magma-8B Text Generator"
)

# Launch the app (use launch instead of mount_gradio_app)
interface.launch()