Spaces:
Build error
Build error
File size: 1,966 Bytes
f57d606 5dee0e8 f57d606 724e3f9 f57d606 |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# -*- coding: utf-8 -*-
"""app.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1va0D7B5cFROqIv6pNnXrWA4-sMWQp_F2
"""
# %pip install torch torchversion torchaudio
# !pip install langchain einop accelerate transformers bitsandbytes
# !pip install langchain-community
from langchain import HuggingFacePipeline
from langchain import PromptTemplate, LLMChain
from transformers import AutoTokenizer, AutoModelForCausalLM
import transformers
import os
import torch
# torch.cuda.is_available()
model_id = "tiiuae/falcon-7b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id,
cache_dir='./workspace/',
torch_dtype=torch.bfloat16,
trust_remote_code=True,
device_map="auto",
offload_folder="offload")
model.eval()
pipeline = transformers.pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
torch_dtype=torch.bfloat16,
trust_remote_code=True,
max_length=2048,
do_sample=True,
top_k=10,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id,
device_map="auto",
)
pipeline("what is a pizza?")
template = PromptTemplate(input_variables=['input'], template='{input}')
llm = HuggingFacePipeline(pipeline=pipeline)
llm_chain = LLMChain(prompt=template, llm=llm)
response = llm_chain.run("what is a pizza?")
print(response)
# !pip install gradio
import gradio as gr
def generate(promt):
return llm_chain.run(promt)
title = 'GYANA.AI'
description = 'Gyana.AI is based on HKRM model it will take 4-5min to ans'
gr.Interface(fn=generate, inputs=['text'], outputs=['text'], title=title, description=description, theme='gstaff/xkcd').launch(share=True) |