Spaces:
Sleeping
Sleeping
first
Browse files
app.py
CHANGED
@@ -1,8 +1,77 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
|
5 |
-
|
6 |
-
demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# def load_css():
|
4 |
+
# with open('app.css', 'r') as file:
|
5 |
+
# return file.read()
|
|
|
6 |
|
7 |
+
def translate_fortran_to_rust(fortran_code):
|
8 |
+
"""Translate Fortran code to Rust using the provided model."""
|
9 |
+
# Translation logic, with example stubbed function call
|
10 |
+
# rust_code = inference.testing(fortran_code)
|
11 |
+
return fortran_code
|
12 |
+
|
13 |
+
default_codes = """
|
14 |
+
program sum_of_numbers\n
|
15 |
+
implicit none\n
|
16 |
+
integer :: n, i, sum\n\n
|
17 |
+
! Initialize variables\n
|
18 |
+
sum = 0\n\n
|
19 |
+
! Get user input\n
|
20 |
+
print *, \Enter a positive integer:\\n
|
21 |
+
read *, n\n\n
|
22 |
+
! Calculate the sum of numbers from 1 to n\n
|
23 |
+
do i = 1, n\n
|
24 |
+
sum = sum + i\n
|
25 |
+
end do\n\n
|
26 |
+
! Print the result\n
|
27 |
+
print *, \The sum of numbers from 1 to\, n, \is\, sum\n
|
28 |
+
end program sum_of_numbers
|
29 |
+
"""
|
30 |
+
|
31 |
+
default_explanation ="""
|
32 |
+
The provided Fortran code snippet is a program that calculates the sum of integers from 1 to n, where n is provided by the user.
|
33 |
+
It uses a simple procedural approach, including variable declarations, input handling, and a loop for the summation.\n\n
|
34 |
+
The functionality of the program is explained in detail in the elaboration. The program starts by initializing variables and prompting the user for input.
|
35 |
+
It then calculates the sum using a do loop, iterating from 1 to n, and accumulating the result in a variable. Finally, it prints the computed sum to the console.\n\n
|
36 |
+
This program demonstrates a straightforward application of Fortran's capabilities for handling loops and basic arithmetic operations.
|
37 |
+
It is a clear example of how Fortran can be used to solve mathematical problems involving user interaction and iterative computations.
|
38 |
+
"""
|
39 |
+
|
40 |
+
# Create the interface
|
41 |
+
|
42 |
+
# Create and launch the Gradio interfac
|
43 |
+
iface = gr.Interface(
|
44 |
+
fn=translate_fortran_to_rust,
|
45 |
+
inputs=[
|
46 |
+
gr.Textbox(
|
47 |
+
lines=10,
|
48 |
+
value="",
|
49 |
+
placeholder="Enter Fortran code here...",
|
50 |
+
label="Fortran Code"
|
51 |
+
),
|
52 |
+
gr.Textbox(
|
53 |
+
lines=10,
|
54 |
+
value="",
|
55 |
+
placeholder="Enter translation explanation here...",
|
56 |
+
label="Fortran Code Explanation"
|
57 |
+
)
|
58 |
+
],
|
59 |
+
outputs=gr.Textbox(
|
60 |
+
lines=10,
|
61 |
+
label="Rust Code"
|
62 |
+
),
|
63 |
+
title="Fortran to Rust Code Translator",
|
64 |
+
description=(
|
65 |
+
"This tool translates Fortran code to Rust using a language model.\n\n"
|
66 |
+
"How to use:\n"
|
67 |
+
"1. Enter your Fortran code in the first text box\n"
|
68 |
+
"2. Add an explanation of the code in the second text box\n"
|
69 |
+
"3. The translated Rust code will appear in the output box\n\n"
|
70 |
+
"Note: The default model is a Llama-3.2-3B-Instruct"
|
71 |
+
),
|
72 |
+
examples=[
|
73 |
+
[default_codes, default_explanation],
|
74 |
+
]
|
75 |
+
)
|
76 |
+
|
77 |
+
iface.launch()
|