celikn commited on
Commit
5e05b1b
·
1 Parent(s): 6ddb6b0

first app

Browse files
Files changed (2) hide show
  1. .gitignore +2 -1
  2. app.py +7 -76
.gitignore CHANGED
@@ -1 +1,2 @@
1
- app_bk.py
 
 
1
+ app_bk.py
2
+ app_bk2.py
app.py CHANGED
@@ -1,81 +1,12 @@
1
- import os
2
  import gradio as gr
3
- from huggingface_hub import InferenceClient, login
4
 
 
 
5
 
6
- # ---- HF token & login integration ----
7
- HF_TOKEN = (os.environ.get("HUGGINGFACE_HUB_TOKEN", "") or "").strip()
8
-
9
- if HF_TOKEN:
10
- # Authenticate this environment (useful for gated models, higher rate limits, etc.)
11
- login(token=HF_TOKEN)
12
- else:
13
- print("UYARI: HF_TOKEN / HUGGINGFACE_HUB_TOKEN bulunamadı, gated modellere erişilemeyebilir.")
14
-
15
-
16
- # Create a single shared client (reuse across requests)
17
- client = InferenceClient(
18
- model="openai/gpt-oss-20b",
19
- token=HF_TOKEN if HF_TOKEN else None, # will still work for public models without token
20
- )
21
-
22
- def respond(
23
- message,
24
- history: list[dict[str, str]],
25
- system_message,
26
- max_tokens,
27
- temperature,
28
- top_p,
29
- ):
30
- """
31
- Streaming chat using Hugging Face Inference API.
32
- History is a list of {"role": "...", "content": "..."} dicts.
33
- """
34
-
35
- # Build messages list
36
- messages = [{"role": "system", "content": system_message}]
37
- messages.extend(history)
38
- messages.append({"role": "user", "content": message})
39
-
40
- response = ""
41
-
42
- # Stream tokens from the model
43
- for chunk in client.chat_completion(
44
- messages=messages,
45
- max_tokens=max_tokens,
46
- stream=True,
47
- temperature=temperature,
48
- top_p=top_p,
49
- ):
50
- choices = chunk.choices
51
- token_text = ""
52
- if len(choices) and choices[0].delta.content:
53
- token_text = choices[0].delta.content
54
-
55
- response += token_text
56
- yield response
57
-
58
-
59
- chatbot = gr.ChatInterface(
60
- respond,
61
- type="messages",
62
- title="Basit Chat Botu",
63
- description="Küçük bir sohbet botu, HF Inference API ile çalışıyor.",
64
- additional_inputs=[
65
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
66
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
67
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
68
- gr.Slider(
69
- minimum=0.1,
70
- maximum=1.0,
71
- value=0.95,
72
- step=0.05,
73
- label="Top-p (nucleus sampling)",
74
- ),
75
- ],
76
  )
77
 
78
- demo = chatbot # no login UI needed now
79
-
80
- if __name__ == "__main__":
81
- demo.launch()
 
 
1
  import gradio as gr
 
2
 
3
+ def selam_ver(isim):
4
+ return f"Merhaba, {isim}!"
5
 
6
+ demo = gr.Interface(
7
+ fn=selam_ver,
8
+ inputs=gr.Textbox(label="İsminiz"),
9
+ outputs=gr.Textbox(label="Selam")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  )
11
 
12
+ demo.launch()