mpolanco commited on
Commit
1092f22
·
verified ·
1 Parent(s): b866537

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -17
app.py CHANGED
@@ -1,20 +1,33 @@
1
- import openai
2
- import gradio
3
 
4
- openai.api_key = "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"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- messages = [{"role": "system", "content": "You are a financial experts that specializes in real estate investment and negotiation"}]
 
 
 
 
 
 
 
7
 
8
- def CustomChatGPT(user_input):
9
- messages.append({"role": "user", "content": user_input})
10
- response = openai.ChatCompletion.create(
11
- model = "gpt-3.5-turbo",
12
- messages = messages
13
- )
14
- ChatGPT_reply = response["choices"][0]["message"]["content"]
15
- messages.append({"role": "assistant", "content": ChatGPT_reply})
16
- return ChatGPT_reply
17
-
18
- demo = gradio.Interface(fn=CustomChatGPT, inputs = "text", outputs = "text", title = "Real Estate Pro")
19
-
20
- demo.launch(share=True)
 
1
+ import gradio as gr
2
+ import requests
3
 
4
+ def generate_response(prompt):
5
+ endpoint = 'https://api.together.xyz/v1/chat/completions'
6
+ headers = {
7
+ "Authorization": "Bearer YOUR_API_KEY",
8
+ }
9
+ payload = {
10
+ "model": "meta-llama/Llama-2-70b-chat-hf",
11
+ "max_tokens": 512,
12
+ "prompt": "[INST] {prompt} [/INST]",
13
+ "request_type": "language-model-inference",
14
+ "temperature": 0.7,
15
+ "top_p": 0.7,
16
+ "top_k": 50,
17
+ "repetition_penalty": 1,
18
+ "stop": ["[/INST]", ""],
19
+ "promptObj": {"prompt": ""},
20
+ }
21
+ response = requests.post(endpoint, json=payload, headers=headers)
22
+ return response.json()["choices"][0]["text"]
23
 
24
+ iface = gr.Interface(
25
+ fn=generate_response,
26
+ inputs="text",
27
+ outputs="text",
28
+ title="Llama Chatbot",
29
+ description="Chat with the Llama chatbot model.",
30
+ example="What is the weather like today?",
31
+ )
32
 
33
+ iface.launch()