lodhrangpt commited on
Commit
222662d
·
verified ·
1 Parent(s): bcd1db7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -37
app.py CHANGED
@@ -4,21 +4,21 @@ import os
4
  from together import Together
5
  import base64
6
  import io
7
- from dotenv import load_dotenv
8
-
9
- # Load environment variables from .env file
10
- load_dotenv()
11
 
12
  # Initialize Together client
13
  client = None
14
- api_key=None
15
  def initialize_client(api_key=None):
16
  global client
17
- # Load the API key from environment if not provided
18
- api_key = os.getenv("TG_API_KEY")
19
  print(api_key)
20
- client = Together()
21
-
 
 
 
 
22
 
23
  def encode_image(image_path):
24
  with Image.open(image_path) as img:
@@ -26,15 +26,13 @@ def encode_image(image_path):
26
  img.save(buffered, format="PNG")
27
  return base64.b64encode(buffered.getvalue()).decode("utf-8")
28
 
29
- def bot_streaming(
30
- message, history
31
- ):
32
- together_api_key=api_key
33
- max_new_tokens=250
34
  temperature=0.7
35
  if client is None:
36
  try:
37
- initialize_client(together_api_key)
38
  except Exception as e:
39
  history.append((message, f"Error initializing client: {str(e)}"))
40
  yield history
@@ -133,34 +131,15 @@ def bot_streaming(
133
 
134
  # The rest of your Gradio interface code remains the same
135
  with gr.Blocks() as demo:
136
- gr.Markdown("# Meta Llama-3.2-11B-Vision-Instruct (FREE)")
137
  gr.Markdown(
138
- "Try the new Llama 3.2 11B Vision API by Meta for free through Together AI. Upload an image, and start chatting about it. Just paste in your Together AI API key and get started!"
139
  )
140
 
141
- with gr.Row():
142
- together_api_key = gr.Textbox(
143
- label="Together API Key",
144
- placeholder="Enter your TOGETHER_API_KEY here",
145
- type="password",
146
- )
147
-
148
- with gr.Row():
149
- # max_new_tokens = gr.Slider(
150
- # minimum=10,
151
- # maximum=10000,
152
- # value=250,
153
- # step=10,
154
- # label="Maximum number of new tokens",
155
- # )
156
- # temperature = gr.Number(
157
- # value=0.7, minimum=0, maximum=1, step=0.1, label="Temperature"
158
- # )
159
-
160
  chatbot = gr.Chatbot()
161
  msg = gr.MultimodalTextbox(label="")
162
  clear = gr.Button("Clear")
163
-
164
  msg.submit(
165
  bot_streaming,
166
  [msg, chatbot],
 
4
  from together import Together
5
  import base64
6
  import io
 
 
 
 
7
 
8
  # Initialize Together client
9
  client = None
10
+
11
  def initialize_client(api_key=None):
12
  global client
13
+ # Fetch the API key from the environment if it's not provided directly
14
+ api_key = api_key or os.getenv("TOGETHER_API_KEY")
15
  print(api_key)
16
+ if api_key:
17
+ os.environ["TOGETHER_API_KEY"] = api_key
18
+ client = Together()
19
+ else:
20
+ raise ValueError("Please provide a Together API Key")
21
+
22
 
23
  def encode_image(image_path):
24
  with Image.open(image_path) as img:
 
26
  img.save(buffered, format="PNG")
27
  return base64.b64encode(buffered.getvalue()).decode("utf-8")
28
 
29
+
30
+ def bot_streaming(message, history):
31
+ max_new_tokens=250
 
 
32
  temperature=0.7
33
  if client is None:
34
  try:
35
+ initialize_client()
36
  except Exception as e:
37
  history.append((message, f"Error initializing client: {str(e)}"))
38
  yield history
 
131
 
132
  # The rest of your Gradio interface code remains the same
133
  with gr.Blocks() as demo:
134
+ gr.Markdown("# Medical Image Analyzer")
135
  gr.Markdown(
136
+ "Upload a medical image, and start chatting about it."
137
  )
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  chatbot = gr.Chatbot()
140
  msg = gr.MultimodalTextbox(label="")
141
  clear = gr.Button("Clear")
142
+
143
  msg.submit(
144
  bot_streaming,
145
  [msg, chatbot],