Dzsysop commited on
Commit
837726c
·
1 Parent(s): 8dbf76b

make app.py to link to AI

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,7 +1,24 @@
 
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
  import gradio as gr
3
+ from huggingface_hub import InferenceClient
4
+ import os
5
 
6
+ client = InferenceClient(token=os.environ.get("HF_TOKEN"))
 
7
 
8
+ def predict(prompt):
9
+ try:
10
+ response = client.text_generation(
11
+ prompt=prompt,
12
+ model="microsoft/phi-2",
13
+ max_new_tokens=100
14
+ )
15
+ return response
16
+ except:
17
+ return "Извините, сервис временно недоступен"
18
+
19
+ gr.Interface(
20
+ fn=predict,
21
+ inputs=gr.Textbox(label="Вопрос к NPC"),
22
+ outputs=gr.Textbox(label="Ответ"),
23
+ title="AI для игры"
24
+ ).launch()