Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained("<lehmanc25>/my-phi2-model")
|
8 |
-
model = AutoModelForCausalLM.from_pretrained("<lehmanc25>/my-phi2-model")
|
9 |
|
10 |
def chat_with_phi2(input_text):
|
11 |
encoded_input = tokenizer(input_text, return_tensors='pt')
|
@@ -13,14 +11,19 @@ def chat_with_phi2(input_text):
|
|
13 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
14 |
return response
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
inputs=gr.Textbox(lines=2, placeholder="Ask something about W&L..."),
|
19 |
-
|
20 |
-
#model(inputs)
|
21 |
-
outputs="text",
|
22 |
-
title="W&L ChatGPT-like AI",
|
23 |
-
description="Ask any question about Washington and Lee University!"
|
24 |
-
)
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
|
4 |
+
# Assuming you've uploaded your model to Hugging Face with the username 'lehmanc25'
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("lehmanc25/my-phi2-model")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("lehmanc25/my-phi2-model")
|
|
|
|
|
7 |
|
8 |
def chat_with_phi2(input_text):
|
9 |
encoded_input = tokenizer(input_text, return_tensors='pt')
|
|
|
11 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
12 |
return response
|
13 |
|
14 |
+
# Using Gradio Blocks to build a more dynamic interface
|
15 |
+
block = gr.Blocks()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
with block:
|
18 |
+
gr.Markdown("# W&L ChatGPT-like AI")
|
19 |
+
gr.Markdown("Ask any question about Washington and Lee University!")
|
20 |
+
input_text = gr.Textbox(label="Your question:", lines=2, placeholder="Ask something about W&L...")
|
21 |
+
output_text = gr.Text(label="AI Response:")
|
22 |
+
button = gr.Button("Ask")
|
23 |
+
button.click(
|
24 |
+
fn=chat_with_phi2,
|
25 |
+
inputs=input_text,
|
26 |
+
outputs=output_text
|
27 |
+
)
|
28 |
|
29 |
+
block.launch()
|