Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,24 @@
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
-
import torch
|
| 5 |
|
| 6 |
-
|
| 7 |
-
"tiiuae/falcon-7b-instruct",
|
| 8 |
-
torch_dtype=torch.bfloat16,
|
| 9 |
-
trust_remote_code=True,
|
| 10 |
-
device_map="auto",
|
| 11 |
-
low_cpu_mem_usage=True,
|
| 12 |
-
)
|
| 13 |
-
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct")
|
| 14 |
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
attention_mask=attention_mask,
|
| 23 |
-
max_length=200,
|
| 24 |
-
do_sample=True,
|
| 25 |
-
top_k=10,
|
| 26 |
-
num_return_sequences=1,
|
| 27 |
-
eos_token_id=tokenizer.eos_token_id,
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 31 |
-
print(output_text)
|
| 32 |
-
|
| 33 |
-
# Remove Prompt Echo from Generated Text
|
| 34 |
-
cleaned_output_text = output_text.replace(input_text, "")
|
| 35 |
-
return cleaned_output_text
|
| 36 |
|
| 37 |
|
| 38 |
text_generation_interface = gr.Interface(
|
| 39 |
-
fn=
|
| 40 |
inputs=[
|
| 41 |
gr.inputs.Textbox(label="Input Text"),
|
| 42 |
],
|
| 43 |
outputs=gr.inputs.Textbox(label="Generated Text"),
|
| 44 |
-
title="
|
| 45 |
|
| 46 |
).launch()
|
|
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
+
import requests
|
|
|
|
| 4 |
|
| 5 |
+
API_TOKEN = os.environ['API_TOKEN']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
+
API_URL = "https://api-inference.huggingface.co/google/gemma-7b"
|
| 9 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
| 10 |
+
def query(payload):
|
| 11 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 12 |
+
return response.json()
|
| 13 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
text_generation_interface = gr.Interface(
|
| 17 |
+
fn=query,
|
| 18 |
inputs=[
|
| 19 |
gr.inputs.Textbox(label="Input Text"),
|
| 20 |
],
|
| 21 |
outputs=gr.inputs.Textbox(label="Generated Text"),
|
| 22 |
+
title="google/gemma-7b",
|
| 23 |
|
| 24 |
).launch()
|