Inan Ince
commited on
Commit
•
ce236d9
1
Parent(s):
1fcacc8
Add application file14
Browse files
app.py
CHANGED
@@ -1,33 +1,24 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
model_name = "
|
6 |
-
|
|
|
7 |
|
8 |
-
# Java
|
9 |
-
def
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
"""
|
15 |
-
result = qa_pipeline({
|
16 |
-
"question": question,
|
17 |
-
"context": context
|
18 |
-
})
|
19 |
-
return result["answer"]
|
20 |
|
21 |
# Gradio UI
|
22 |
with gr.Blocks() as demo:
|
23 |
-
gr.Markdown("<h1 style='text-align: center;'>Java
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
btn =
|
28 |
-
answer = gr.Textbox(label="Yanıt")
|
29 |
-
|
30 |
-
btn.click(answer_java_question, inputs=[question, context], outputs=answer)
|
31 |
|
32 |
demo.launch()
|
33 |
-
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
# CodeT5 modelini yükleyin
|
5 |
+
model_name = "Salesforce/codet5-base"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
8 |
|
9 |
+
# Java kodu üretme fonksiyonu
|
10 |
+
def generate_java_code(prompt):
|
11 |
+
inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)
|
12 |
+
outputs = model.generate(inputs["input_ids"], max_length=150, num_beams=4, early_stopping=True)
|
13 |
+
code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
return code
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Gradio UI
|
17 |
with gr.Blocks() as demo:
|
18 |
+
gr.Markdown("<h1 style='text-align: center;'>Java Kod Üretici</h1>")
|
19 |
+
prompt = gr.Textbox(label="Java kodu için doğal dil açıklaması", placeholder="Örnek: 2 sayıdan büyüğünü getiren bir Java kodu yaz.")
|
20 |
+
output_code = gr.Textbox(label="Üretilen Java Kodu", lines=10)
|
21 |
+
btn = gr.Button("Kod Üret")
|
22 |
+
btn.click(generate_java_code, inputs=prompt, outputs=output_code)
|
|
|
|
|
|
|
23 |
|
24 |
demo.launch()
|
|