X-014 commited on
Commit
d675cf7
·
verified ·
1 Parent(s): 27e6260

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the Zephyr 7B Beta model
5
+ pipe = pipeline(
6
+ "text-generation",
7
+ model="HuggingFaceH4/zephyr-7b-beta",
8
+ device_map="auto"
9
+ )
10
+
11
+ # API function
12
+ def chat_api(prompt):
13
+ # Generate a response from the model
14
+ result = pipe(
15
+ prompt,
16
+ max_new_tokens=200,
17
+ do_sample=True,
18
+ temperature=0.7,
19
+ top_p=0.9
20
+ )
21
+ return result[0]["generated_text"]
22
+
23
+ # Create Gradio Interface for API access (no UI needed)
24
+ demo = gr.Interface(
25
+ fn=chat_api,
26
+ inputs=gr.Textbox(label="Prompt"),
27
+ outputs=gr.Textbox(label="Response"),
28
+ allow_flagging="never"
29
+ )
30
+
31
+ # Launch with API enabled
32
+ demo.launch(server_name="0.0.0.0", server_port=7860)