OnlyCheeini
commited on
Commit
•
0d78aa2
1
Parent(s):
7737d3e
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,31 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
raise HTTPException(status_code=400, detail="Model not found")
|
33 |
-
|
34 |
-
inputs = tokenizer(request.prompt, return_tensors="pt").to(device)
|
35 |
-
outputs = model.generate(
|
36 |
-
**inputs,
|
37 |
-
max_length=inputs['input_ids'].shape[1] + request.max_tokens,
|
38 |
-
temperature=request.temperature,
|
39 |
-
top_p=request.top_p,
|
40 |
-
)
|
41 |
-
|
42 |
-
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
43 |
-
return OpenAIResponse(choices=[{"text": generated_text}])
|
44 |
-
|
45 |
-
if __name__ == "__main__":
|
46 |
-
import uvicorn
|
47 |
-
import gradio as gr
|
48 |
-
|
49 |
-
def greet(name, req: gr.Request):
|
50 |
-
return f"{req.headers=}"
|
51 |
-
|
52 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
53 |
-
iface.launch()
|
54 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
|
4 |
+
def get_ip(space_url):
|
5 |
+
try:
|
6 |
+
# Use the ping command to get the IP address
|
7 |
+
result = subprocess.run(["ping", "-c", "1", space_url], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
8 |
+
output = result.stdout
|
9 |
+
|
10 |
+
# Extract the IP address from the output
|
11 |
+
start = output.find("(") + 1
|
12 |
+
end = output.find(")")
|
13 |
+
ip_address = output[start:end]
|
14 |
+
|
15 |
+
if not ip_address:
|
16 |
+
return "Failed to retrieve IP address."
|
17 |
+
|
18 |
+
return ip_address
|
19 |
+
except Exception as e:
|
20 |
+
return str(e)
|
21 |
+
|
22 |
+
# Gradio interface
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=get_ip,
|
25 |
+
inputs="text",
|
26 |
+
outputs="text",
|
27 |
+
title="Get Hugging Face Space IP Address",
|
28 |
+
description="Enter the URL of your Hugging Face Space (e.g., your-space-url.hf.space) to retrieve its IP address."
|
29 |
+
)
|
30 |
+
|
31 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|