Tri4 commited on
Commit
6dcddee
·
verified ·
1 Parent(s): bb15562

Rename main.py to chatapi-v1.py

Browse files
Files changed (1) hide show
  1. main.py → chatapi-v1.py +64 -0
main.py → chatapi-v1.py RENAMED
@@ -1,3 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from flask import Flask, request, jsonify
2
  from huggingface_hub import InferenceClient
3
 
 
1
+ """
2
+ Inference
3
+
4
+
5
+ import requests
6
+ import json
7
+
8
+ def send_request_to_flask(prompt, history, temperature=0.7, max_new_tokens=100, top_p=0.9, repetition_penalty=1.2):
9
+ # URL of the Flask endpoint
10
+ url = "https://jikoni-llamasms.hf.space/generate" # Adjust the URL if needed
11
+
12
+ # Create the payload
13
+ payload = {
14
+ "prompt": prompt,
15
+ "history": history,
16
+ "temperature": temperature,
17
+ "max_new_tokens": max_new_tokens,
18
+ "top_p": top_p,
19
+ "repetition_penalty": repetition_penalty
20
+ }
21
+
22
+ try:
23
+ # Send the POST request
24
+ response = requests.post(url, json=payload)
25
+
26
+ # Check if the request was successful
27
+ if response.status_code == 200:
28
+ result = response.json()
29
+ return result["response"]
30
+ else:
31
+ print("Failed to get response from Flask app.")
32
+ print("Status Code:", response.status_code)
33
+ print("Response Text:", response.text)
34
+ return None
35
+
36
+ except requests.RequestException as e:
37
+ print("An error occurred:", e)
38
+ return None
39
+
40
+ if __name__ == "__main__":
41
+ history = [] # Initialize an empty history list
42
+
43
+ while True:
44
+ # Prompt the user for input
45
+ prompt = input("You: ")
46
+
47
+ if prompt.lower() in ['exit', 'quit', 'stop']:
48
+ print("Exiting the chat.")
49
+ break
50
+
51
+ # Send request and get response
52
+ response_text = send_request_to_flask(prompt, history)
53
+
54
+ if response_text:
55
+ print("Response from Flask app:")
56
+ print(response_text)
57
+ # Update history
58
+ history.append((prompt, response_text))
59
+ else:
60
+ print("No response received.")
61
+
62
+ """
63
+
64
+
65
  from flask import Flask, request, jsonify
66
  from huggingface_hub import InferenceClient
67