Delete prompt.py
Browse files
prompt.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
# نقرأ التوكين من الـ Secret (ما منكتبه في الكود)
|
| 6 |
-
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
-
|
| 8 |
-
# أنشئ عميل Hugging Face مع الموديل المطلوب
|
| 9 |
-
client = InferenceClient(model="google/flan-t5-base", token=HF_TOKEN)
|
| 10 |
-
|
| 11 |
-
def generate_response(prompt, method):
|
| 12 |
-
if method == "Zero-shot":
|
| 13 |
-
system_prompt = f"Answer the question: {prompt}"
|
| 14 |
-
elif method == "Few-shot":
|
| 15 |
-
system_prompt = (
|
| 16 |
-
"Example 1: Q: Capital of France? A: Paris\n"
|
| 17 |
-
"Example 2: Q: Largest planet? A: Jupiter\n"
|
| 18 |
-
f"Q: {prompt} A:"
|
| 19 |
-
)
|
| 20 |
-
else: # Chain-of-thought
|
| 21 |
-
system_prompt = f"Think step by step before answering: {prompt}"
|
| 22 |
-
|
| 23 |
-
# استدعاء الموديل
|
| 24 |
-
response = client.text_generation(system_prompt, max_new_tokens=200)
|
| 25 |
-
return response
|
| 26 |
-
|
| 27 |
-
# واجهة Gradio
|
| 28 |
-
with gr.Blocks() as demo:
|
| 29 |
-
gr.Markdown("## LLM Playground - Hugging Face API")
|
| 30 |
-
|
| 31 |
-
with gr.Row():
|
| 32 |
-
prompt = gr.Textbox(label="Enter your prompt")
|
| 33 |
-
method = gr.Radio(["Zero-shot", "Few-shot", "Chain-of-thought"], label="Prompting Method")
|
| 34 |
-
|
| 35 |
-
output = gr.Textbox(label="Model Output")
|
| 36 |
-
|
| 37 |
-
btn = gr.Button("Generate")
|
| 38 |
-
btn.click(fn=generate_response, inputs=[prompt, method], outputs=output)
|
| 39 |
-
|
| 40 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|