File size: 932 Bytes
8a97208
c928ad3
8272482
c928ad3
 
12ea1ed
319b4d3
c928ad3
 
 
319b4d3
402975e
c928ad3
 
 
 
319b4d3
0010001
8a97208
0010001
 
 
eb443cd
 
4789c94
c928ad3
 
 
 
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
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer

# Specify the directory containing the model and tokenizer
model_name = "gpt4all"  # Make sure this matches the actual model directory
model_path = f"./"  # Path to the model directory

# Initialize the GPT-4 model and tokenizer
model = AutoModelForCausalLM.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)

def generate_text(input_text):
    input_ids = tokenizer(input_text, return_tensors="pt").input_ids
    generated_ids = model.generate(input_ids)
    generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
    return generated_text

text_generation_interface = gr.Interface(
    fn=generate_text,
    inputs=[
        gr.inputs.Textbox(label="Input Text"),
    ],
    outputs=gr.outputs.Textbox(label="Generated Text"),
    title="GPT-4 Text Generation",
).launch()



# model_name = ""