File size: 1,818 Bytes
dbe195e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
"""huggingface.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/149y_UsrqsIDR7_OwRgNnRfs-KkGhFvtx
"""

from transformers import pipeline

generator = pipeline("text-generation",
                     model= "Qwen/Qwen3-4B-Instruct-2507",
                     torch_dtype="auto",
                     device_map="auto")

output = generator("Hi how are you?")
print(output[0]["generated_text"])

messages = [
	{"role": "system", "content": "You are a helpful AI assistant."},
    {"role": "user", "content": "Tell me a short joke"}]

outputs = generator(
        messages,
        max_new_tokens=100,
        do_sample=True,
        temperature=0.7,
        return_full_text=False
)

print(outputs[0]["generated_text"])

messages = [
    {
        "role": "system",
        "content": "Sen Türkçe cevap veren, yardımcı bir yapay zeka asistansın."
    },
    {
        "role": "user",
        "content": "Üretken yapay zeka nedir kısaca cevap ver"
    }
]

outputs = generator(
        messages,
        max_new_tokens=100,
        do_sample=True,
        temperature=0.7,
        return_full_text=False
)
print(outputs[0]["generated_text"])

import gradio as gr

def generate_text(prompt):
  messages = [
        {"role": "system", "content": "Sen Türkçe cevap veren, yardımcı bir yapay zeka asistansın."},
        {"role": "user", "content": prompt}]
  outputs = generator(
        messages,
        max_new_tokens=200,
        do_sample=True,
        temperature=0.7,
        return_full_text=False
    )
  return outputs[0]["generated_text"]

demo = gr.Interface(
    fn=generate_text,
    inputs=gr.Textbox(label="Give an input"),
    outputs=gr.Textbox(label="Output"),
    title="Text Generation",)
demo.launch()