File size: 1,000 Bytes
2fd3831
7a75a15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2fd3831
7a75a15
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from grouped_sampling import GroupedSamplingPipeLine


def create_pipeline(model_name: str, group_size) -> GroupedSamplingPipeLine:
    """
    Creates a pipeline with the given model name and group size.
    :param model_name: The name of the model to use.
    :param group_size: The size of the groups to use.
    :return: A pipeline with the given model name and group size.
    """
    return GroupedSamplingPipeLine(
        model_name=model_name,
        group_size=group_size,
        end_of_sentence_stop=True,
    )


@st.cache
def on_form_submit(model_name: str, group_size: int, prompt: str) -> str:
    """
    Called when the user submits the form.
    :param model_name: The name of the model to use.
    :param group_size: The size of the groups to use.
    :param prompt: The prompt to use.
    :return: The output of the model.
    """
    pipeline = create_pipeline(
        model_name,
        group_size,
    )
    return pipeline(prompt)["generated_text"]