File size: 1,446 Bytes
722177d
8fe6ab2
921a7bd
722177d
921a7bd
 
3aaf394
 
19e4851
921a7bd
 
 
 
 
80ca826
626064c
921a7bd
626064c
 
 
 
 
 
 
 
921a7bd
19e4851
921a7bd
626064c
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
import gradio as gr
import spaces
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load model and tokenizer
model_name = "infly/OpenCoder-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)

@spaces.GPU
def generate_text(prompt):
    inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True)
    outputs = model.generate(inputs["input_ids"], max_length=100, num_return_sequences=1)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

iface = gr.Interface(
    fn=generate_text,
    inputs=[
        gr.Textbox(label="Enter your prompt", placeholder="Start typing...", lines=5),
        gr.Slider(minimum=50, maximum=200, value=100, step=1, label="Max Length"),
        gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
    ],
    outputs="text",
    title="OpenCoder 8B Instruct",
    description="Generate text using the OpenCoder model. Adjust the settings and input a prompt to generate responses.",
)

# Launch the Gradio app
iface.launch(share=True)
    
# Create Gradio interface
# interface = gr.Interface(
#     fn=generate_text,
#     inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
#     outputs=gr.Textbox(label="Generated Text")
# )

# # Launch the Gradio app
# if __name__ == "__main__":
#     interface.launch()