File size: 1,145 Bytes
3643b73
95b2a11
dc09589
db46f1f
d591ad9
3643b73
 
db46f1f
 
 
0b7787a
3ddf3ff
3d9d5b5
0b7787a
d591ad9
95b2a11
a3606dd
 
 
573cd07
a3606dd
d591ad9
 
 
 
 
 
dc09589
d591ad9
da2c202
 
dc09589
 
d591ad9
 
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
33
34
35
import os
import torch
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, QuantoConfig

access_token = os.environ["GATED_ACCESS_TOKEN"]

quantization_config = QuantoConfig(
    weights = "int4"
)

model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1", quantization_config=quantization_config, device_map="auto", token=access_token)
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1", token = access_token)

# Function to generate text using the model
def generate_text(prompt):
    text = prompt
    inputs = tokenizer(text, return_tensors="pt")
    
    outputs = model.generate(**inputs, max_new_tokens=512)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

# Create the Gradio interface
iface = gr.Interface(
    fn=generate_text,
    inputs=[
        gr.inputs.Textbox(lines=5, label="Input Prompt"),
    ],
    outputs=gr.outputs.Textbox(label="Generated Text"),
    title="MisTRAL Text Generation",
    description="Use this interface to generate text using the MisTRAL language model.",
)

# Launch the Gradio interface
iface.launch()