Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -45,7 +45,7 @@ text_tokenizer = AutoTokenizer.from_pretrained(
|
|
45 |
with torch.no_grad():
|
46 |
tuned_phi2 = AutoModelForCausalLM.from_pretrained(
|
47 |
"stage2_adaptor", trust_remote_code=True,
|
48 |
-
|
49 |
)
|
50 |
base_phi2_text = AutoModelForCausalLM.from_pretrained(
|
51 |
phi_model_name, trust_remote_code=True,
|
@@ -93,12 +93,14 @@ def process_audio(audio):
|
|
93 |
|
94 |
def generate_response(image, audio, text, count):
|
95 |
count = int(count)
|
|
|
96 |
if audio:
|
97 |
text_from_audio = process_audio(audio)
|
98 |
if text:
|
99 |
overall_input = text + text_from_audio
|
100 |
if image:
|
101 |
img_tokens = process_image(image)
|
|
|
102 |
q_tokens = text_tokenizer.encode(
|
103 |
overall_input,
|
104 |
return_tensors='pt').to(device)
|
@@ -120,10 +122,7 @@ def generate_response(image, audio, text, count):
|
|
120 |
else:
|
121 |
return process_text(overall_input, count)
|
122 |
|
123 |
-
return prediction[0].strip('<|endoftext|>').rstrip("\n")
|
124 |
|
125 |
-
|
126 |
-
%%blocks
|
127 |
with gr.Blocks() as demo:
|
128 |
gr.Markdown("# **AnyModeAssistant**")
|
129 |
gr.Markdown("Use any mode text/image/audio to interact with AI assistant")
|
|
|
45 |
with torch.no_grad():
|
46 |
tuned_phi2 = AutoModelForCausalLM.from_pretrained(
|
47 |
"stage2_adaptor", trust_remote_code=True,
|
48 |
+
device_map="auto",
|
49 |
)
|
50 |
base_phi2_text = AutoModelForCausalLM.from_pretrained(
|
51 |
phi_model_name, trust_remote_code=True,
|
|
|
93 |
|
94 |
def generate_response(image, audio, text, count):
|
95 |
count = int(count)
|
96 |
+
|
97 |
if audio:
|
98 |
text_from_audio = process_audio(audio)
|
99 |
if text:
|
100 |
overall_input = text + text_from_audio
|
101 |
if image:
|
102 |
img_tokens = process_image(image)
|
103 |
+
overall_input = "Question: " + overall_input + "Answer:"
|
104 |
q_tokens = text_tokenizer.encode(
|
105 |
overall_input,
|
106 |
return_tensors='pt').to(device)
|
|
|
122 |
else:
|
123 |
return process_text(overall_input, count)
|
124 |
|
|
|
125 |
|
|
|
|
|
126 |
with gr.Blocks() as demo:
|
127 |
gr.Markdown("# **AnyModeAssistant**")
|
128 |
gr.Markdown("Use any mode text/image/audio to interact with AI assistant")
|