Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,7 @@ import torch
|
|
4 |
import os
|
5 |
|
6 |
# Retrieve the token from environment variables
|
7 |
-
api_token = os.getenv("HF_TOKEN")
|
8 |
-
if not api_token:
|
9 |
-
raise ValueError("HF_TOKEN environment variable is not set. Please set it to your Hugging Face API token.")
|
10 |
-
api_token = api_token.strip()
|
11 |
|
12 |
# Model name
|
13 |
model_name = "ContactDoctor/Bio-Medical-MultiModal-Llama-3-8B-V1"
|
@@ -36,6 +33,10 @@ def generate_response(input_text):
|
|
36 |
# Ensure input tensor is sent to the same device as the model
|
37 |
input_ids = inputs["input_ids"].to(model.device)
|
38 |
|
|
|
|
|
|
|
|
|
39 |
# Generate a response using the model
|
40 |
outputs = model.generate(
|
41 |
input_ids,
|
@@ -65,4 +66,4 @@ iface = gr.Interface(
|
|
65 |
|
66 |
# Launch the Gradio app
|
67 |
if __name__ == "__main__":
|
68 |
-
iface.launch(
|
|
|
4 |
import os
|
5 |
|
6 |
# Retrieve the token from environment variables
|
7 |
+
api_token = os.getenv("HF_TOKEN").strip()
|
|
|
|
|
|
|
8 |
|
9 |
# Model name
|
10 |
model_name = "ContactDoctor/Bio-Medical-MultiModal-Llama-3-8B-V1"
|
|
|
33 |
# Ensure input tensor is sent to the same device as the model
|
34 |
input_ids = inputs["input_ids"].to(model.device)
|
35 |
|
36 |
+
# Add batch dimension (if missing)
|
37 |
+
if len(input_ids.shape) == 1: # If shape is (seq_len,)
|
38 |
+
input_ids = input_ids.unsqueeze(0) # Add batch dimension: (1, seq_len)
|
39 |
+
|
40 |
# Generate a response using the model
|
41 |
outputs = model.generate(
|
42 |
input_ids,
|
|
|
66 |
|
67 |
# Launch the Gradio app
|
68 |
if __name__ == "__main__":
|
69 |
+
iface.launch()
|