File size: 628 Bytes
6978631
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

def generate_response(input_text):
    model_name = "cognitivecomputations/dolphin-2.1-mistral-7b"
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

    inputs = tokenizer(input_text, return_tensors="pt")
    outputs = model.generate(**inputs, max_length=200, num_beams=5, early_stopping=True)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)

    return response

iface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
iface.launch()