File size: 1,072 Bytes
4be87b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain.prompts import PromptTemplate
from langchain.llms import CTransformers
import os
import gradio as gr

def GetLlamaResponse(topic):
    llm = CTransformers(
        model_type="google-flan",
        model="tf_model.h5",
        config={"max_new_tokens": 64, "temperature": 0.75},
    )
    template = """
    You are a helpful assistant
    """
    prompt = PromptTemplate(
        input_variables=["topic", "word_count", "temperature"],
        template=template,
    )

    response = llm(
        prompt.format(
            word_count=64,
            temperature=0.4,
            topic=topic,
        )
    )

    return response

inputs_image_url = [
    gr.Textbox(type="text", label="Topic Name"),
]

outputs_result_dict = [
    gr.Textbox(type="text", label="Result"),
]

interface_image_url = gr.Interface(
    fn=GetLlamaResponse,
    inputs=inputs_image_url,
    outputs=outputs_result_dict,
    title="Text Generation",
    cache_examples=False,
)

gr.TabbedInterface(
    [interface_image_url],
    tab_names=['Some inference']
).queue().launch()