naughtondale commited on
Commit
e6f9186
·
1 Parent(s): bae87f6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import gradio as gr
4
+
5
+ def run_llama_v2(prompt):
6
+ api_token = os.environ.get('REPLICATE_API_TOKEN')
7
+ if not api_token:
8
+ raise ValueError("REPLICATE_API_TOKEN environment variable not set.")
9
+
10
+ headers = {
11
+ 'Authorization': f'Bearer {api_token}',
12
+ }
13
+
14
+ url = 'https://api.replicate.ai/v1/runs/replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1'
15
+ payload = {
16
+ 'input': {
17
+ 'prompt': prompt,
18
+ }
19
+ }
20
+
21
+ response = requests.post(url, headers=headers, json=payload)
22
+
23
+ if response.status_code == 200:
24
+ return response.json()
25
+ else:
26
+ raise Exception(f"Error running the model: {response.status_code} - {response.text}")
27
+
28
+ iface = gr.Interface(
29
+ fn=run_llama_v2,
30
+ inputs=gr.inputs.Textbox(prompt="Type here..."),
31
+ outputs=gr.outputs.JSON(),
32
+ live=True,
33
+ title="Hugging Face Chatbot",
34
+ description="Interact with the Hugging Face Llama v2 chatbot model.",
35
+ )
36
+
37
+ if __name__ == "__main__":
38
+ iface.launch()