bjoernix commited on
Commit
6bb6794
โ€ข
1 Parent(s): a0f67c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -12,7 +12,7 @@ def encode_image(img):
12
 
13
  def chat_with_pixtral(uploaded_file, user_question):
14
  if uploaded_file is not None:
15
- # uploaded_file์€ ์ด๋ฏธ PIL ์ด๋ฏธ์ง€ ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.
16
  base64_img = encode_image(uploaded_file)
17
 
18
  api = "https://api.hyperbolic.xyz/v1/chat/completions"
@@ -28,7 +28,7 @@ def chat_with_pixtral(uploaded_file, user_question):
28
  {
29
  "role": "user",
30
  "content": [
31
- {"type": "text", "text": user_question}, # ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ์งˆ๋ฌธ
32
  {
33
  "type": "image_url",
34
  "image_url": {"url": f"data:image/jpeg;base64,{base64_img}"},
@@ -44,25 +44,25 @@ def chat_with_pixtral(uploaded_file, user_question):
44
 
45
  response = requests.post(api, headers=headers, json=payload)
46
 
47
- # API ์‘๋‹ต ํ™•์ธ
48
  if response.status_code == 200:
49
  response_data = response.json()
50
  if 'choices' in response_data:
51
  assistant_response = response_data['choices'][0]['message']['content']
52
  else:
53
- assistant_response = "์‘๋‹ต ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค."
54
  else:
55
- assistant_response = f"API ์š”์ฒญ ์‹คํŒจ: {response.status_code} - {response.text}"
56
 
57
  return assistant_response
58
- return "์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ์งˆ๋ฌธ์„ ์ž…๋ ฅํ•˜์„ธ์š”."
59
 
60
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
61
  iface = gr.Interface(
62
  fn=chat_with_pixtral,
63
  inputs=[
64
- gr.Image(type="pil", label="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜์„ธ์š”"),
65
- gr.Textbox(label="์งˆ๋ฌธ์„ ์ž…๋ ฅํ•˜์„ธ์š”")
66
  ],
67
  outputs="text",
68
  title="Pixtral Image Chat",
 
12
 
13
  def chat_with_pixtral(uploaded_file, user_question):
14
  if uploaded_file is not None:
15
+ # uploaded_file ist bereits ein PIL-Bildobjekt.
16
  base64_img = encode_image(uploaded_file)
17
 
18
  api = "https://api.hyperbolic.xyz/v1/chat/completions"
 
28
  {
29
  "role": "user",
30
  "content": [
31
+ {"type": "text", "text": user_question}, # Vom Benutzer eingegebene Fragen
32
  {
33
  "type": "image_url",
34
  "image_url": {"url": f"data:image/jpeg;base64,{base64_img}"},
 
44
 
45
  response = requests.post(api, headers=headers, json=payload)
46
 
47
+ # Prรผfen der API-Antwort
48
  if response.status_code == 200:
49
  response_data = response.json()
50
  if 'choices' in response_data:
51
  assistant_response = response_data['choices'][0]['message']['content']
52
  else:
53
+ assistant_response = "Antwortformat ist falsch."
54
  else:
55
+ assistant_response = f"Fehlerhafte API-Anforderung: {response.status_code} - {response.text}"
56
 
57
  return assistant_response
58
+ return "Laden Sie ein Bild hoch und geben Sie Ihre Frage ein."
59
 
60
+ # Gradio Einstellungen der Schnittstelle
61
  iface = gr.Interface(
62
  fn=chat_with_pixtral,
63
  inputs=[
64
+ gr.Image(type="pil", label="Ein Bild hochladen"),
65
+ gr.Textbox(label="Ihre Frage eingeben")
66
  ],
67
  outputs="text",
68
  title="Pixtral Image Chat",