File size: 1,718 Bytes
8a97208
8272482
 
c12b438
319b4d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8272482
c12b438
 
 
8272482
402975e
 
319b4d3
 
 
 
 
 
 
 
 
 
8a97208
402975e
0010001
8a97208
0010001
 
 
eb443cd
 
402975e
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer

# Specify the path to your fine-tuned model and tokenizer
# model_path = "./"  # Assuming the model is in the same directory as your notebook
# model_name = "https://huggingface.co/spaces/DR-Rakshitha/wizardlm_api/blob/main/pytorch_model-00001-of-00002.bin"  # Replace with your model name

from llama_cpp import Llama 
import timeit

# Load Llama 2 model
llm = Llama(model_path="./pytorch_model-00001-of-00002.bin",
            n_ctx=512,
            n_batch=128)

# Start timer
start = timeit.default_timer()

# Generate LLM response
# prompt = "What is Python?"

# output = llm(prompt,
#              max_tokens=-1,
#              echo=False,
#              temperature=0.1,
#              top_p=0.9)


# Load the model and tokenizer
model = AutoModelForCausalLM.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)

# Define the function for text generation
def generate_text(input_text):
    # input_ids = tokenizer(input_text, return_tensors="pt").input_ids
    # output = model.generate(input_ids, max_length=50, num_return_sequences=1)
    # generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
    # return generated_text

    output = llm(input_text,
             max_tokens=-1,
             echo=False,
             temperature=0.1,
             top_p=0.9)

# Create the Gradio interface
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 the Gradio interface
text_generation_interface.launch()