Dooratre commited on
Commit
fa21e2d
·
verified ·
1 Parent(s): ac9ffc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -70
app.py CHANGED
@@ -1,73 +1,12 @@
1
- import requests
2
- from flask import Flask, render_template, request
3
 
 
4
 
5
- app = Flask(__name__)
6
- with open('i.txt', 'r') as file:
7
- data = file.read()
8
- API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
9
- headers = {"Authorization": f"Bearer hf{data}"}
10
 
11
-
12
- def query(payload):
13
- response = requests.post(API_URL, headers=headers, json=payload)
14
- return response.json()
15
-
16
- conversation_history = []
17
-
18
- def generate_response(user_input):
19
- new_query = {
20
- "inputs": f"you are ai created by Mr,Omar Nuwara he is made you \n\n start chat with omar and ask him or answer him you are free with him \n\ntask:complete the reesponse:\n\nconversation history:{conversation_history}\n\nomar message:{user_input}\n\nmake sure to response about it and don't generate alot of words just based on the user message \n\n\n\nresponse:",
21
- "parameters": {
22
- "top_k": 50,
23
- "top_p": 0.9,
24
- "temperature": 0.1,
25
- "repetition_penalty": 1.2,
26
- "max_new_tokens": 512,
27
- "max_time": 0,
28
- "return_full_text": True,
29
- "num_return_sequences": 1,
30
- "do_sample": False
31
- },
32
- "options": {
33
- "use_cache": False,
34
- "wait_for_model": False
35
- }
36
- }
37
-
38
- output = query(new_query)
39
-
40
- generated_text = output[0]['generated_text']
41
-
42
- response_start = generated_text.find('response:') + len('response:')
43
- response_end = generated_text.find('(end response)')
44
-
45
- response_text = generated_text[response_start:response_end].strip()
46
-
47
- note_index = response_text.find("Note:")
48
- if note_index != -1:
49
- response_text = response_text[:note_index].strip()
50
-
51
- instruction_index = response_text.find("### Instruction:")
52
- if instruction_index != -1:
53
- response_text = response_text[:instruction_index].strip()
54
-
55
- return response_text
56
-
57
- @app.route('/')
58
- def index():
59
- return render_template('index.html',data=data)
60
-
61
- @app.route('/chat', methods=['POST'])
62
- def chat():
63
- user_input = request.form['user_input']
64
-
65
- # Generate AI response based on user input
66
- response_text = generate_response(user_input)
67
- conversation_history.append({"omar": user_input, "AI": response_text})
68
-
69
- return response_text
70
-
71
-
72
- if __name__ == '__main__':
73
- app.run(host="0.0.0.0", port=7860)
 
1
+ import g4f
 
2
 
3
+ prompt = 'hello sir'
4
 
5
+ response = g4f.ChatCompletion.create(
6
+ model="gpt-4",
7
+ messages=[{"role": "user", "content": prompt}],
8
+ stream=True,
9
+ )
10
 
11
+ for message in response:
12
+ print(message, flush=True, end='')