Spaces:
Build error
Build error
File size: 1,839 Bytes
e188d84 699c9ba 9f381ba 11e5816 63c220f 11e5816 699c9ba 11e5816 e64e956 6c85cff e64e956 699c9ba b579bc3 e64e956 699c9ba e64e956 |
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 |
!wget -q https://github.com/PanQiWei/AutoGPTQ/releases/download/v0.4.1/auto_gptq-0.4.1+cu118-cp310-cp310-linux_x86_64.whl
!BUILD_CUDA_EXT=0 pip install -qqq auto_gptq-0.4.1+cu118-cp310-cp310-linux_x86_64.whl --progress-bar off
import gradio as gr
from auto_gptq import AutoGPTQForCausalLM
from transformers import AutoTokenizer, TextStreamer
title = "Npradhaph"
examples = [
["The tower is 324 metres (1,063 ft) tall,"],
["The Moon's orbit around Earth has"],
["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
]
# Load the trained model
model_path = "huggingface/pradhaph/medical-falcon-7b"
model = AutoGPTQForCausalLM.from_quantized(
model_path,
revision="main",
# revision="gptq-8bit-128g-actorder_True",
model_basename="model",
use_safetensors=True,
trust_remote_code=True,
inject_fused_attention=False,
device_map="cuda",
quantize_config=None,
)
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=True)
# Define the input and output interfaces
def answer_question(context):
# Generate an answer based on the context
inputs = tokenizer(context, return_tensors="pt", max_length=512, truncation=True)
outputs = model.generate(**inputs, max_length=200, num_return_sequences=1)
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
return answer
# Run the interface
iface = gr.Interface(
fn=answer_question,
inputs="text",
outputs="text",
title="Question Answering with GPT",
description="Enter a context to get an answer."
)
# demo = gr.load(
# "huggingface/pradhaph/medical-falcon-7b",
# inputs=gr.Textbox(lines=5, max_lines=6, label="Input Text"),
# title=title,
# examples=examples,
# trust_remote_code=True,
# )
if __name__ == "__main__":
iface.launch()
# demo.launch() |