nicole-ait commited on
Commit
bea420f
1 Parent(s): 6266928

init w/ hf models

Browse files
Files changed (3) hide show
  1. .gitignore +5 -0
  2. app.py +43 -0
  3. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ .vscode
2
+ __pycache__
3
+
4
+ docker-compose.yml
5
+ Dockerfile
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from langchain import PromptTemplate, LLMChain
4
+ from langchain.llms import HuggingFaceHub
5
+
6
+ template = """Question: {question}
7
+
8
+ Answer: Let's think step by step."""
9
+
10
+
11
+ def run(
12
+ question: gr.Textbox = None,
13
+ repo_id: gr.Dropdown = None,
14
+ temperature: gr.Slider = 0.5,
15
+ max_length: gr.Slider = 64,
16
+ ):
17
+ prompt = PromptTemplate(template=template, input_variables=["question"])
18
+ llm = HuggingFaceHub(
19
+ repo_id=repo_id,
20
+ model_kwargs={"temperature": temperature, "max_length": max_length}
21
+ )
22
+ llm_chain = LLMChain(prompt=prompt, llm=llm)
23
+ result = llm_chain.run(question)
24
+ print(result)
25
+ return result
26
+
27
+
28
+ inputs = [
29
+ gr.Textbox(label="Question"),
30
+ gr.Dropdown(["google/flan-t5-xxl", "google/flan-t5-base"],
31
+ value="google/flan-t5-xxl", label="Model", allow_custom_value=True),
32
+ gr.Slider(0.0, 1.0, value=0.5, step=0.05, label="Temperature"),
33
+ gr.Slider(10, 1000, value=64, label="Max Length"),
34
+ ]
35
+
36
+ title = "Langchain w/ HF Models"
37
+
38
+ gr.Interface(
39
+ fn=run,
40
+ inputs=inputs,
41
+ outputs='label',
42
+ title=title,
43
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ langchain
2
+ huggingface_hub