File size: 1,246 Bytes
7d29a02
 
8f9d959
7d29a02
 
 
8f9d959
775cc38
7d29a02
 
 
8f9d959
7d29a02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76a1fac
 
7d29a02
 
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
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
from gradio import gr

MODEL_NAME = "allenai/cosmo-xl"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)


def generate_text(situation, instructions, prompt):
    """
    Generate text using the specified model and inputs.

    Args:
        situation: A short description of the context or situation.
        instructions: Specific instructions or constraints for text generation.
        prompt: The initial text prompt for the model to start from.

    Returns:
        The generated text.
    """
    inputs = tokenizer([situation, instructions, prompt], return_tensors="pt")
    outputs = model.generate(**inputs)
    generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return generated_text


interface = gr.Interface(
    generate_text,
    [
        gr.Textbox(label="Situation"),
        gr.Textbox(label="Instructions"),
        gr.Textbox(label="Prompt"),
    ],
    "textbox",
    theme="huggingface",
    title="Cosmopolitan Conversationalist",
    description="Generate creative text with context and instructions!",
)

interface.launch(server_name="Cosmopolitan_Conversationalist")