Spaces:
Sleeping
Sleeping
Mohammed-Altaf
commited on
Commit
•
be9ad62
1
Parent(s):
1aa0dad
added data files
Browse files- .gitignore +1 -0
- README.md +1 -1
- app.py +54 -0
- requirements.txt +5 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv
|
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Medicare Api
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: Medicare Api
|
3 |
+
emoji: 😷
|
4 |
colorFrom: yellow
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import torch
|
4 |
+
|
5 |
+
model_id = None
|
6 |
+
|
7 |
+
if model_id:
|
8 |
+
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
10 |
+
model_id,
|
11 |
+
torch_dtype=torch.bfloat16,
|
12 |
+
trust_remote_code=True,
|
13 |
+
device_map="auto",
|
14 |
+
low_cpu_mem_usage=True,
|
15 |
+
)
|
16 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
17 |
+
else:
|
18 |
+
model = 'We have not downloaded model yet'
|
19 |
+
tokenizer = 'we have not downloaded the tokenizer yet'
|
20 |
+
|
21 |
+
|
22 |
+
def generate_text(input_text):
|
23 |
+
if model_id:
|
24 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
25 |
+
attention_mask = torch.ones(input_ids.shape)
|
26 |
+
|
27 |
+
output = model.generate(
|
28 |
+
input_ids,
|
29 |
+
attention_mask=attention_mask,
|
30 |
+
max_length=200,
|
31 |
+
do_sample=True,
|
32 |
+
top_k=10,
|
33 |
+
num_return_sequences=1,
|
34 |
+
eos_token_id=tokenizer.eos_token_id,
|
35 |
+
)
|
36 |
+
|
37 |
+
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
38 |
+
print(output_text)
|
39 |
+
else:
|
40 |
+
output_text = model
|
41 |
+
print(model)
|
42 |
+
# Remove Prompt Echo from Generated Text
|
43 |
+
cleaned_output_text = output_text.replace(input_text, "")
|
44 |
+
return cleaned_output_text
|
45 |
+
|
46 |
+
|
47 |
+
text_generation_interface = gr.Interface(
|
48 |
+
fn=generate_text,
|
49 |
+
inputs=[
|
50 |
+
gr.inputs.Textbox(label="Input Text"),
|
51 |
+
],
|
52 |
+
outputs=gr.inputs.Textbox(label="Generated Text"),
|
53 |
+
title="Falcon-7B Instruct",
|
54 |
+
).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
datasets
|
2 |
+
transformers
|
3 |
+
accelerate
|
4 |
+
einops
|
5 |
+
safetensors
|