Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
-
from PIL import Image
|
4 |
import pytesseract
|
5 |
|
|
|
6 |
huggingface-cli login
|
7 |
|
8 |
-
# Initialize chat model
|
9 |
-
chat_model = pipeline("text-generation", model="gpt2") #
|
10 |
-
|
11 |
-
# Use a pipeline as a high-level helper
|
12 |
-
from transformers import pipeline
|
13 |
-
|
14 |
-
messages = [
|
15 |
-
{"role": "user", "content": "Who are you?"},
|
16 |
-
]
|
17 |
-
pipe = pipeline("text-generation", model="meta-llama/Llama-3.3-70B-Instruct")
|
18 |
-
pipe(messages)
|
19 |
-
# Load model directly
|
20 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
21 |
|
|
|
22 |
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.3-70B-Instruct")
|
23 |
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.3-70B-Instruct")
|
|
|
24 |
# Chat function
|
25 |
def chat_fn(history, user_input):
|
26 |
conversation = {"history": history, "user": user_input}
|
@@ -54,4 +45,5 @@ with gr.Blocks() as demo:
|
|
54 |
msg.submit(chat_fn, [chatbot, msg], [chatbot, msg])
|
55 |
clear.click(lambda: None, None, chatbot)
|
56 |
|
|
|
57 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
|
|
3 |
import pytesseract
|
4 |
|
5 |
+
# Login to huggingface CLI
|
6 |
huggingface-cli login
|
7 |
|
8 |
+
# Initialize chat model (You can change the model here)
|
9 |
+
chat_model = pipeline("text-generation", model="gpt2") # You can switch to any model of your choice
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Initialize LLaMA model for more advanced instruction-following tasks
|
12 |
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.3-70B-Instruct")
|
13 |
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.3-70B-Instruct")
|
14 |
+
|
15 |
# Chat function
|
16 |
def chat_fn(history, user_input):
|
17 |
conversation = {"history": history, "user": user_input}
|
|
|
45 |
msg.submit(chat_fn, [chatbot, msg], [chatbot, msg])
|
46 |
clear.click(lambda: None, None, chatbot)
|
47 |
|
48 |
+
# Launch the Gradio interface
|
49 |
demo.launch()
|