Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
torch_dtype=torch.float16,
|
| 11 |
-
device_map="auto"
|
| 12 |
)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
messages.append({"role": "user", "content": user_msg})
|
| 24 |
-
messages.append({"role": "assistant", "content": bot_msg})
|
| 25 |
-
|
| 26 |
-
# Yeni mesajı ekleme
|
| 27 |
-
messages.append({"role": "user", "content": message})
|
| 28 |
-
|
| 29 |
-
# Tokenize etme
|
| 30 |
-
inputs = tokenizer.apply_chat_template(
|
| 31 |
-
messages,
|
| 32 |
-
return_tensors="pt"
|
| 33 |
-
).to(model.device)
|
| 34 |
-
|
| 35 |
-
# Yanıt üretme
|
| 36 |
-
outputs = model.generate(
|
| 37 |
-
inputs,
|
| 38 |
-
max_new_tokens=512,
|
| 39 |
-
temperature=0.7,
|
| 40 |
-
top_p=0.95,
|
| 41 |
-
do_sample=True
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
# Yanıtı decode etme
|
| 45 |
-
response = tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)
|
| 46 |
-
|
| 47 |
-
return response
|
| 48 |
-
|
| 49 |
-
# Gradio arayüzü
|
| 50 |
-
demo = gr.ChatInterface(
|
| 51 |
-
fn=predict,
|
| 52 |
-
title="Sağlık Danışmanı Chatbot (Gemma 3)",
|
| 53 |
-
description="Bu chatbot, sağlık, beslenme ve egzersiz konularında bilgi vermek için tasarlanmıştır. Tıbbi teşhis koymaz veya reçete önermez.",
|
| 54 |
-
theme="soft"
|
| 55 |
)
|
| 56 |
|
| 57 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
pipe = pipeline(
|
| 6 |
+
"image-text-to-text",
|
| 7 |
+
model="rahul7star/gemma-3bit",
|
| 8 |
+
device="cpu",
|
| 9 |
+
torch_dtype=torch.bfloat16
|
|
|
|
|
|
|
| 10 |
)
|
| 11 |
|
| 12 |
+
def chat(image, prompt):
|
| 13 |
+
messages = [
|
| 14 |
+
{"role": "user", "content": [{"type": "image", "image": image}, {"type": "text", "text": prompt}]}
|
| 15 |
+
]
|
| 16 |
+
out = pipe(text=messages, max_new_tokens=200)
|
| 17 |
+
return out[0]["generated_text"][-1]["content"]
|
| 18 |
|
| 19 |
+
demo = gr.Interface(
|
| 20 |
+
fn=chat,
|
| 21 |
+
inputs=[gr.Image(type="pil"), gr.Textbox(label="Prompt")],
|
| 22 |
+
outputs=gr.Textbox(label="Response"),
|
| 23 |
+
title="Gemma 3 4B‑IT Vision‑Text Chat",
|
| 24 |
+
description="Upload an image and ask questions using Google’s gems!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
+
demo.launch()
|