Atulit23 commited on
Commit
4be87b6
·
verified ·
1 Parent(s): 93898b2

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. app.py +13 -27
  2. app1.py +49 -0
  3. requirements.txt +2 -1
app.py CHANGED
@@ -1,31 +1,17 @@
1
- from langchain.prompts import PromptTemplate
2
- from langchain.llms import CTransformers
3
- import os
4
  import gradio as gr
5
 
6
- def GetLlamaResponse(topic):
7
- llm = CTransformers(
8
- model_type="google-flan",
9
- model="tf_model.h5",
10
- config={"max_new_tokens": 64, "temperature": 0.75},
11
- )
12
- template = """
13
- You are a helpful assistant
14
- """
15
- prompt = PromptTemplate(
16
- input_variables=["topic", "word_count", "temperature"],
17
- template=template,
18
- )
19
-
20
- response = llm(
21
- prompt.format(
22
- word_count=64,
23
- temperature=0.4,
24
- topic=topic,
25
- )
26
- )
27
-
28
- return response
29
 
30
  inputs_image_url = [
31
  gr.Textbox(type="text", label="Topic Name"),
@@ -36,7 +22,7 @@ outputs_result_dict = [
36
  ]
37
 
38
  interface_image_url = gr.Interface(
39
- fn=GetLlamaResponse,
40
  inputs=inputs_image_url,
41
  outputs=outputs_result_dict,
42
  title="Text Generation",
 
1
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
 
 
2
  import gradio as gr
3
 
4
+ model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
5
+ tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
6
+
7
+ def index(prompt):
8
+ inputs = tokenizer(prompt, return_tensors="pt")
9
+ outputs = model.generate(**inputs)
10
+
11
+ print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
12
+
13
+ return tokenizer.batch_decode(outputs, skip_special_tokens=True)
14
+
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  inputs_image_url = [
17
  gr.Textbox(type="text", label="Topic Name"),
 
22
  ]
23
 
24
  interface_image_url = gr.Interface(
25
+ fn=index,
26
  inputs=inputs_image_url,
27
  outputs=outputs_result_dict,
28
  title="Text Generation",
app1.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.prompts import PromptTemplate
2
+ from langchain.llms import CTransformers
3
+ import os
4
+ import gradio as gr
5
+
6
+ def GetLlamaResponse(topic):
7
+ llm = CTransformers(
8
+ model_type="google-flan",
9
+ model="tf_model.h5",
10
+ config={"max_new_tokens": 64, "temperature": 0.75},
11
+ )
12
+ template = """
13
+ You are a helpful assistant
14
+ """
15
+ prompt = PromptTemplate(
16
+ input_variables=["topic", "word_count", "temperature"],
17
+ template=template,
18
+ )
19
+
20
+ response = llm(
21
+ prompt.format(
22
+ word_count=64,
23
+ temperature=0.4,
24
+ topic=topic,
25
+ )
26
+ )
27
+
28
+ return response
29
+
30
+ inputs_image_url = [
31
+ gr.Textbox(type="text", label="Topic Name"),
32
+ ]
33
+
34
+ outputs_result_dict = [
35
+ gr.Textbox(type="text", label="Result"),
36
+ ]
37
+
38
+ interface_image_url = gr.Interface(
39
+ fn=GetLlamaResponse,
40
+ inputs=inputs_image_url,
41
+ outputs=outputs_result_dict,
42
+ title="Text Generation",
43
+ cache_examples=False,
44
+ )
45
+
46
+ gr.TabbedInterface(
47
+ [interface_image_url],
48
+ tab_names=['Some inference']
49
+ ).queue().launch()
requirements.txt CHANGED
@@ -3,4 +3,5 @@ uvicorn
3
  ctransformers
4
  langchain
5
  python-box
6
- gradio
 
 
3
  ctransformers
4
  langchain
5
  python-box
6
+ gradio
7
+ transformers