File size: 1,763 Bytes
87ce80f d8ff437 77d3dbe 87ce80f 7b6d332 fab8ffe 8f1cf32 4e4190b 8f1cf32 fab8ffe 4e4190b 8f1cf32 4e4190b 8f1cf32 4e4190b 8e1991d 8f1cf32 4e4190b 8f1cf32 4e4190b 8f1cf32 4e4190b e719a30 4e4190b 8e1991d 4e4190b 8e1991d b5de101 8e1991d b5de101 e719a30 dceb63e 8e1991d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import gradio as gr
from gradio_client import Client, handle_file
from huggingface_hub import InferenceClient
moondream_client = Client("vikhyatk/moondream2")
llama_client = InferenceClient("Qwen/QwQ-32B-Preview")
history = []
def describe_image(image, user_message):
global history
result = moondream_client.predict(
img=handle_file(image),
prompt="Describe this image.",
api_name="/answer_question"
)
description = result # Moondream2'nin cevabını alıyoruz
history.append(f"User: {user_message}")
history.append(f"Assistant: {description}")
full_conversation = "\n".join(history)
llama_result = llama_client.chat_completion(
messages=[{"role": "user", "content": full_conversation}],
max_tokens=512,
temperature=0.7,
top_p=0.95
)
return description + "\n\nAssistant: " + llama_result['choices'][0]['message']['content']
def chat_or_image(image, user_message):
global history
if image:
return describe_image(image, user_message)
else:
history.append(f"User: {user_message}")
full_conversation = "\n".join(history)
llama_result = llama_client.chat_completion(
messages=[{"role": "user", "content": full_conversation}],
max_tokens=512,
temperature=0.7,
top_p=0.95
)
return llama_result['choices'][0]['message']['content']
demo = gr.Interface(
fn=chat_or_image,
inputs=[
gr.Image(type="filepath", label="Resim Yükle (isteğe bağlı)"),
gr.Textbox(label="Soru Sor ya da Konuş", placeholder="Soru sor...", lines=2)
],
outputs="text",
)
if __name__ == "__main__":
demo.launch(show_error=True) |