Spaces:
Build error
Build error
changes add trusted mode
Browse files
app.py
CHANGED
@@ -8,13 +8,50 @@ examples = [
|
|
8 |
["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
|
9 |
]
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
trust_remote_code=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
)
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
if __name__ == "__main__":
|
20 |
-
|
|
|
|
8 |
["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
|
9 |
]
|
10 |
|
11 |
+
import gradio as gr
|
12 |
+
from auto_gptq import AutoGPTQForCausalLM
|
13 |
+
from transformers import AutoTokenizer, TextStreamer
|
14 |
+
|
15 |
+
# Load the trained model
|
16 |
+
model_path = "huggingface/pradhaph/medical-falcon-7b"
|
17 |
+
model = AutoGPTQForCausalLM.from_quantized(
|
18 |
+
model_path,
|
19 |
+
revision="main",
|
20 |
+
# revision="gptq-8bit-128g-actorder_True",
|
21 |
+
model_basename="model",
|
22 |
+
use_safetensors=True,
|
23 |
trust_remote_code=True,
|
24 |
+
inject_fused_attention=False,
|
25 |
+
device_map="cuda",
|
26 |
+
quantize_config=None,
|
27 |
+
)
|
28 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=True)
|
29 |
+
|
30 |
+
# Define the input and output interfaces
|
31 |
+
def answer_question(context):
|
32 |
+
# Generate an answer based on the context
|
33 |
+
inputs = tokenizer(context, return_tensors="pt", max_length=512, truncation=True)
|
34 |
+
outputs = model.generate(**inputs, max_length=200, num_return_sequences=1)
|
35 |
+
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
36 |
+
return answer
|
37 |
+
|
38 |
+
# Run the interface
|
39 |
+
iface = gr.Interface(
|
40 |
+
fn=answer_question,
|
41 |
+
inputs="text",
|
42 |
+
outputs="text",
|
43 |
+
title="Question Answering with GPT",
|
44 |
+
description="Enter a context to get an answer."
|
45 |
)
|
46 |
|
47 |
+
# demo = gr.load(
|
48 |
+
# "huggingface/pradhaph/medical-falcon-7b",
|
49 |
+
# inputs=gr.Textbox(lines=5, max_lines=6, label="Input Text"),
|
50 |
+
# title=title,
|
51 |
+
# examples=examples,
|
52 |
+
# trust_remote_code=True,
|
53 |
+
# )
|
54 |
+
|
55 |
if __name__ == "__main__":
|
56 |
+
iface.launch()
|
57 |
+
# demo.launch()
|