placed just the generation into ui for llama3-8b
Browse files- app.py +61 -1
- requirements.txt +2 -1
app.py
CHANGED
@@ -3,4 +3,64 @@ import pandas as pd
|
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
5 |
import re
|
6 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
5 |
import re
|
6 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
7 |
+
import re
|
8 |
+
from huggingface_hub import login
|
9 |
+
import os
|
10 |
+
|
11 |
+
# HF_TOKEN
|
12 |
+
TOKEN = os.getenv('HF_AUTH_TOKEN')
|
13 |
+
login(token=TOKEN,
|
14 |
+
add_to_git_credential=False)
|
15 |
+
|
16 |
+
# Open ai api key
|
17 |
+
API_KEY = os.getenv('OPEN_AI_API_KEY')
|
18 |
+
|
19 |
+
DESCRIPTION = '''
|
20 |
+
<div>
|
21 |
+
<h1 style="text-align: center;">Amphisbeana π</h1>
|
22 |
+
<p>This uses Llama 3 and GPT-4o as generation, both of these make the final generation. <a href="https://huggingface.co/meta-llama/Meta-Llama-3-8B"><b>Llama3-8b</b></a>and <a href="https://platform.openai.com/docs/models/gpt-4o"><b>GPT-4o</b></a></p>
|
23 |
+
</div>
|
24 |
+
'''
|
25 |
+
|
26 |
+
# Place transformers in hardware to prepare for process and generation
|
27 |
+
llama_tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B")
|
28 |
+
llama_model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B", token=TOKEN, torch_dtype=torch.float16).to('cuda')
|
29 |
+
|
30 |
+
# Place just input pass and return generation output
|
31 |
+
def llama_generation(input_text):
|
32 |
+
"""
|
33 |
+
Pass input texts, tokenize, output and back to text.
|
34 |
+
"""
|
35 |
+
|
36 |
+
input_ids = llama_tokenizer.encode(input_text,
|
37 |
+
return_tensors='pt')
|
38 |
+
|
39 |
+
output_ids = llama_model.generate(**input_ids)
|
40 |
+
|
41 |
+
# Decode
|
42 |
+
output_text = llama_tokenizer.decode(output_ids,
|
43 |
+
skip_special_tokens=True)
|
44 |
+
|
45 |
+
return output_text
|
46 |
+
|
47 |
+
# Let's just make sure the llama is returning as it should and than place that return output into a function making it fit into a base
|
48 |
+
# Prompt for gpt-4o
|
49 |
+
|
50 |
+
chatbot=gr.Chatbot(height=600, label="Amphisbeana AI")
|
51 |
+
|
52 |
+
with gr.Blocks(fill_height=True) as demo:
|
53 |
+
gr.Markdown(DESCRIPTION)
|
54 |
+
gr.ChatInterface(
|
55 |
+
fn=llama_generation,
|
56 |
+
chatbot=chatbot,
|
57 |
+
fill_height=True,
|
58 |
+
examples=["Make a poem of batman inside willy wonka",
|
59 |
+
"How can you a burrito with just flour?",
|
60 |
+
"How was saturn formed in 3 sentences",
|
61 |
+
"How does the frontal lobe effect playing soccer"],
|
62 |
+
cache_examples=False
|
63 |
+
)
|
64 |
+
|
65 |
+
if __name__ == "__main__":
|
66 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -3,4 +3,5 @@ pandas
|
|
3 |
numpy
|
4 |
gradio
|
5 |
transformers
|
6 |
-
openai
|
|
|
|
3 |
numpy
|
4 |
gradio
|
5 |
transformers
|
6 |
+
openai
|
7 |
+
huggingface_hub
|